Here you can find the source of getStringTokens(String str)
public static String[] getStringTokens(String str)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004 Actuate Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w .j a v a2 s . c o m*/ * Actuate Corporation - initial API and implementation *******************************************************************************/ import java.util.ArrayList; public class Main { public static String[] getStringTokens(String str) { // No ESC, return API results if (str.indexOf("\\,") < 0) //$NON-NLS-1$ { return str.split(","); //$NON-NLS-1$ } ArrayList<String> list = new ArrayList<String>(); char[] charArray = (str + ",").toCharArray(); //$NON-NLS-1$ int startIndex = 0; for (int i = 0; i < charArray.length; i++) { char c = charArray[i]; if (c == ',') { if (charArray[i - 1] != '\\' && i > 0) { list.add(str.substring(startIndex, i).replaceAll("\\\\,", ",") //$NON-NLS-1$ //$NON-NLS-2$ .trim()); startIndex = i + 1; } } } return list.toArray(new String[list.size()]); } }