import java.util.Vector; import java.util.Enumeration; public class StringUtil { public static Vector split(String s) { return split(s, ' '); } public static Vector split(String s, char delim) { Vector rv = new Vector(); int i = 0; while( i < s.length() ) { StringBuffer buf = new StringBuffer(); // Skip leading delimiters. while( (i < s.length()) && (s.charAt(i) == delim) ) { ++i; } // Each new non-delimiter is part of this element of the // split string. char ch; while( (i < s.length()) && ((ch = s.charAt(i)) != delim) ) { buf.append(ch); ++i; } rv.add(buf.toString()); } return rv; } public static String join(Vector components) { return join(components, ' '); } public static String join(Vector components, char delim) { StringBuffer rv = new StringBuffer(); Enumeration e = components.elements(); for( int i = 0 ; e.hasMoreElements() ; ++i ) { if( i != 0 ) { rv.append(delim); } rv.append(e.nextElement()); } return rv.toString(); } }