How to spilled string that contins string in Quote in java -


i find function in java spilled string need make save quote symbol in output

like example:

hello "string type"

the output be:

hello
i
am
string type

expected output:

hello
i
am
"string type"

public static string[] split(string str) { str += " "; // detect last token when not quoted... arraylist<string> strings = new arraylist<string>(); boolean inquote = false; stringbuilder sb = new stringbuilder(); (int = 0; < str.length(); i++) {     char c = str.charat(i);     if (c == '"' || c == ' '|| c=='\n' && !inquote) {         if (c == '"')             inquote = !inquote;         if (!inquote && sb.length() > 0) {             strings.add(sb.tostring());             sb.delete(0, sb.length());         }     } else         sb.append(c); } return strings.toarray(new string[strings.size()]);} 

any idea improve function thank you,


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -