Here you can find the source of splitArrayStringQuoted(String array, char quoteChar)
Parameter | Description |
---|---|
array | Input string, containing quoted character sets. |
quoteChar | The character used to quote strings in the input string. |
public static List<String> splitArrayStringQuoted(String array, char quoteChar)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { /**//w ww . j a v a 2s . co m * Takes a string and splits it according to the quote character '.<br> * Use this method for splitting a string into several parts, where each part corresponds to a quoted substring in the input.<br> * A string "['stringA' 'stringB']" will result in the list (stringA,stringB) with ' being the character used for qouting. * @param array Input string, containing quoted character sets. * @param quoteChar The character used to quote strings in the input string. * @return list, containing all quotes strings in the input string. */ public static List<String> splitArrayStringQuoted(String array, char quoteChar) { array = array.replace("[", ""); array = array.replace("]", ""); List<String> result = new ArrayList<>(); Integer actStart = null; for (int i = 0; i < array.length(); i++) { if (array.charAt(i) == quoteChar) { if (actStart == null) { if (i < array.length() - 1) { actStart = i + 1; } } else { result.add(array.substring(actStart, i)); actStart = null; } } } return result; } /** * Takes a string and splits it according to the quote character.<br> * Use this method for splitting a string into several parts, where each part corresponds to a quoted substring in the input.<br> * A string "['stringA' 'stringB']" will result in the list (stringA,stringB) with ' being the character used for qouting. * @param array Input string, containing quoted character sets. * @return list, containing all quotes strings in the input string. */ public static List<String> splitArrayStringQuoted(String array) { return splitArrayStringQuoted(array, '\''); } }