Utilities for strings.
* * * Copyright 2002 Sapient * @since carbon 1.0 * @author Greg Hinkle, May 2002 * @version $Revision: 1.5 $($Author: dvoet $ / $Date: 2003/05/05 21:21:24 $) */ public class StringUtil { /** * Parses a comma-separated list into an array of Strings * Values can contain whitespace, but whitespace at the beginning and * end of each value is trimmed. * @return array of Strings * @param csvList a string of comma seperated values */ public static String[] parseCommaDelimitedList(String csvList) { String[] result = parseList(csvList, ","); for (int i = 0; i < result.length; i++) { result[i] = result[i].trim(); } return result; } /** * Parses a whitepsace-separated list into an array of Strings * @return array of Strings * @param wsvList a string of white space seperated values */ public static String[] parseWhitespaceDelimitedList(String wsvList) { return parseList(wsvList, "\t "); } /** * Parses a list according to the specified delimiter into an * array of Strings. * @see java.util.StringTokenizer * @param list a string of token seperated values * @param delim the delimiter character(s). Each character in the string is a * single delimeter. * @return an array of strings */ public static String[] parseList(String list, String delim) { List result = new ArrayList(); StringTokenizer tokenizer = new StringTokenizer(list, delim); while (tokenizer.hasMoreTokens()) { result.add(tokenizer.nextToken()); } return (String[]) result.toArray(new String[0]); } }