Java Utililty Methods String Split by Line

List of utility methods to do String Split by Line

Description

The list of methods to do String Split by Line are organized into topic(s).

Method

String[]splitBySeparatorAndParen(String line, char sep)
Split using a separator, but allow for the separator to occur in nested parentheses without splitting.
boolean withinQuotes = false;
String newLine = new String(line);
Vector temp = new Vector();
int startIndex = 0;
int nesting = 0;
for (int i = 0; i < newLine.length(); i++) {
    char c = newLine.charAt(i);
    if (c == '"') {
...
String[]splitBySeparatorQuoteAndParen(String line, char sep)
Split using a separator, but allow for the separator to occur in nested parentheses without splitting.
boolean withinQuotes = false;
String newLine = new String(line);
Vector temp = new Vector();
StringBuffer nextString = new StringBuffer();
int nesting = 0;
for (int i = 0; i < newLine.length(); i++) {
    char c = newLine.charAt(i);
    if (c == '\\') {
...
String[]splitCommandLine(String str, boolean extract)
split Command Line
List list = new ArrayList();
int slen;
char c;
int i = 0;
int tokstart = 0;
if ((str == null) || ((str = str.trim()).length() == 0)) {
    return new String[0];
slen = str.length();
while (true) {
    if (i < slen) {
        c = str.charAt(i);
    } else {
        c = '\0';
    if (c == BACKSLASH) {
        i++;
        if (i < slen) {
            i++;
    } else if (c == QUOTE) {
        i = skipSingleQuoted(str, slen, ++i);
    } else if (c == DOUBLEQUOTE) {
        i = skipDoubleQuoted(str, slen, ++i);
    } else if ((c == '\0') || spctabnl(c)) {
        String token = str.substring(tokstart, i);
        if (extract) {
            token = extractQuoted(token);
        list.add(token);
        while ((i < slen) && spctabnl(str.charAt(i))) {
            i++;
        if (i < slen) {
            tokstart = i;
        } else {
            break;
    } else {
        i++;
return (String[]) list.toArray(new String[list.size()]);
String[]splitCommaSeparated(String line)
split Comma Separated
List<String> result = new ArrayList<String>();
StringBuilder item = new StringBuilder();
boolean inQuote = false;
for (int i = 0; i < line.length(); ++i) {
    char ch = line.charAt(i); 
    switch (ch) {
    case '"':
        inQuote = !inQuote;
...
ListsplitHiddenNewLine(String s)
split Hidden New Line
return Arrays.asList(s.split("" + hiddenNewLine()));
int[]splitInt(String line, String seperator, int def)
split Int
String[] ss = split(line, seperator);
int[] r = new int[ss.length];
for (int i = 0; i < r.length; ++i) {
    r[i] = convertInt(ss[i], def);
return r;
ListsplitIntoLines(String str)
Returns an array of strings, one for each line in the string.
ArrayList strings = new ArrayList();
int len = str.length();
if (len == 0) {
    strings.add("");
    return strings;
int lineStart = 0;
for (int i = 0; i < len; ++i) {
...
ArrayListsplitIntoNonEmptyLines(String s)
split Into Non Empty Lines
return removeEmptyLines(s.split("\n"));
ArrayListsplitIntoNonEmptyLinesWithoutNetLogoComments(String s)
split Into Non Empty Lines Without Net Logo Comments
return removeNetLogoCommentsAndEmptyLines(s.split("\n"));
ListsplitLine(final String line, final char delimiter, final char qualifier, final int initialSize)
Returns an ArrayList of items in a delimited string.
final List list = new ArrayList(initialSize);
if (delimiter == 0) {
    list.add(line);
    return list;
} else if (line == null) {
    return list;
String trimmedLine;
...