Java String Split split(String cmd)

Here you can find the source of split(String cmd)

Description

split

License

Open Source License

Declaration

public static String[] split(String cmd) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;

import java.util.List;

public class Main {
    private static final String NUMBER_PREFIX = "<n:";
    private static final String NUMBER_SUFFIX = ">";

    public static String[] split(String cmd) {
        List<String> splitList = new ArrayList<String>();
        split(splitList, cmd);/*  w  ww.  ja va2  s  .c o m*/
        return splitList.toArray(new String[splitList.size()]);
    }

    public static void split(List<String> splitList, String cmd) {
        int number_start = cmd.indexOf(NUMBER_PREFIX);
        if (number_start != -1) {
            int number_end = cmd.indexOf(NUMBER_SUFFIX, number_start);
            if (number_end != -1) {
                if (number_start > 0)
                    splitList.add(cmd.substring(0, number_start));
                number_end += NUMBER_SUFFIX.length();
                splitList.add(cmd.substring(number_start, number_end));
                if (number_end < cmd.length()) {
                    String remain = cmd.substring(number_end);
                    split(splitList, remain);
                }
            } else {
                splitList.add(cmd);
            }
        } else {
            splitList.add(cmd);
        }
    }
}

Related

  1. split(final String text, final String sp)
  2. split(final String toSplit)
  3. split(Iterable objects, boolean even)
  4. split(String arg)
  5. split(String candidate)
  6. split(String content)
  7. Split(String content, String sub_seq)
  8. split(String input)
  9. split(String input)