Here you can find the source of parseArgs(String text)
static public List<String> parseArgs(String text)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { static public List<String> parseArgs(String text) { List<String> args = new ArrayList<String>(); boolean inQuotes = false; boolean inEscape = false; StringBuilder element = new StringBuilder(); char[] charArray = text.toCharArray(); for (int i = 0; i < charArray.length; i++) { char c = charArray[i]; if (c == '"' && !inEscape) { inQuotes = !inQuotes; //Toggle on/off inQuotes continue; }/* w w w .j a va 2s. com*/ if (!inQuotes && c == ' ') { args.add(element.toString()); element = new StringBuilder(); continue; } if (c == '\\' && !inEscape) { inEscape = true; continue; } else { inEscape = false; } element.append(c); } if (!element.toString().equalsIgnoreCase("")) { args.add(element.toString()); } return args; } }