Java String Split by Line splitToPairs(String Line)

Here you can find the source of splitToPairs(String Line)

Description

split To Pairs

License

Open Source License

Declaration

public static String[] splitToPairs(String Line) 

Method Source Code

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

import java.util.ArrayList;

public class Main {
    public static String[] splitToPairs(String Line) {
        Line = Line.replace(" + ", ", ");
        ArrayList<String> result = new ArrayList<>();
        boolean foundQwote = false;
        String pair = "";
        for (int idx = 0; idx < Line.length(); idx++) {
            if (Line.charAt(idx) == '"') {
                foundQwote = !foundQwote;
            } else if (Line.charAt(idx) == ',') {
                if (!foundQwote) {
                    result.add(pair.trim());
                    pair = "";
                } else {
                    pair = pair + Line.charAt(idx);
                }/* ww w . j  a  v  a 2  s.  c  o  m*/
            } else {
                pair = pair + Line.charAt(idx);
            }
        }
        result.add(pair.trim());
        return result.toArray(new String[result.size()]);
    }
}

Related

  1. splitString(String line)
  2. splitStringPerWord(String string, int wordsPerLine)
  3. splitter(String line, char delimeter)
  4. splitToLines(CharSequence str)
  5. splitToLines(final String str)
  6. stringSplit(String line, String delimiter)