Java String Split stringSplit(String s)

Here you can find the source of stringSplit(String s)

Description

string Split

License

Open Source License

Declaration

public static String[] stringSplit(String s) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String[] stringSplit(String s) {
        List<String> f = new ArrayList<>();

        int p = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == ' ') {
                f.add(s.substring(p, i));
                p = i + 1;/*  ww  w.  j a v  a 2 s  . c  om*/
                while (i < s.length() - 1 && s.charAt(i + 1) == ' ') {
                    i++;
                    p++;
                }
            } else if (s.charAt(i) == '`') {
                if (s.substring(i, Math.min(i + 3, s.length())).equals("```")) {
                    int start = i + 3;
                    i += 3;
                    while (i < s.length() - 3 && !s.substring(i, Math.min(i + 3, s.length())).equals("```")) {
                        i++;
                    }
                    if (s.substring(i, Math.min(i + 3, s.length())).equals("```")) {
                        int end = i;
                        f.add(s.substring(start, end));
                        i += 3;
                        p = i;
                    } else { // unterminated
                        f.add(s.substring(start, i));
                    }
                }
            } else if (s.charAt(i) == '\n' || s.charAt(i) == '\r' && s.charAt(i + 1) == '\n') {
                f.add(s.substring(p, i + 1));
                p = i + 1;
            }
        }
        f.add(s.substring(p));

        return f.toArray(new String[f.size()]);
    }
}

Related

  1. splitValues(String value)
  2. splitVersion(String version)
  3. splitWithoutEscaped(String str, String sep)
  4. splitWS(String s, boolean decode)
  5. splitws(String val)
  6. stringSplit(String string, String tokens, boolean trimStrings)
  7. stringSplitter(String string)