Here you can find the source of splitQuotedStr(String str, char delimiter, char quote, boolean trim)
public static List<String> splitQuotedStr(String str, char delimiter, char quote, boolean trim)
//package com.java2s; /******************************************************************************* * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 *******************************************************************************/ import java.util.ArrayList; import java.util.List; public class Main { public static List<String> splitQuotedStr(String str, char delimiter, char quote, boolean trim) { int startPos = 0; boolean insideQuotation = false; List<String> result = new ArrayList<String>(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == quote) { insideQuotation = !insideQuotation; }//from ww w . j a v a 2 s.c o m if (!insideQuotation && c == delimiter) { String subStr = str.substring(startPos, i); if (trim) { subStr = subStr.trim(); } result.add(subStr); startPos = i + 1; continue; } } if (startPos < str.length()) { String subStr = str.substring(startPos, str.length()); if (trim) { subStr = subStr.trim(); } result.add(subStr); } return result; } }