Java Reference
In-Depth Information
String [] split(String source - string) {
// First get rid of whitespace at start and end of the
// string
String string = source - string.trim();
// If string contains no tokens, return a zero length
// array.
if(string.length () == 0) return (new String [0]);
// Use a Vector to collect the unknown number of
// tokens.
Vector token - vector = new Vector();
String token;
int index - a = 0;
int index - b = 0;
// Then scan through the string for the tokens.
while(true) {
index - b = string.indexOf ( '' , index - a);
if (index - b == -1) {
token = string.substring (index - a);
token - vector.addElement (token);
break;
}
token = string.substring (index - a, index - b);
token.trim ();
if (token.length () >= 1)
token - vector.addElement (token);
index - a = index - b+1;
}
// Copy elements into a string array.
String [] str - array =
new String[token - vector.size ()];
for(int i=0; i < str - array.length; i++)
str - array[i] =
(String) (token - vector.elementAt (i));
return str - array;
} // split
} // class Worker
 
Search WWH ::




Custom Search