Here you can find the source of splitArguments(String string)
public static String[] splitArguments(String string)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; public class Main { /** Split command line into arguments. Allows " for words containing whitespaces. */ public static String[] splitArguments(String string) { assert string != null; ArrayList<String> result = new ArrayList<String>(); boolean escape = false; boolean inString = false; StringBuilder token = new StringBuilder(); for (int i = 0; i < string.length(); ++i) { char c = string.charAt(i); if (c == '"' && !escape) { if (inString) { result.add(token.toString()); token.setLength(0);/*from ww w . j ava 2s . c o m*/ } inString = !inString; } else if (Character.isWhitespace(c) && !inString) { if (token.length() > 0) { result.add(token.toString()); token.setLength(0); } } else token.append(c); escape = (c == '\\' && !escape); } if (token.length() > 0) result.add(token.toString()); return result.toArray(new String[result.size()]); } }