1 2 package ch.ethz.ssh2.util; 3 4 10 public class Tokenizer 11 { 12 20 public static String [] parseTokens(String source, char delimiter) 21 { 22 int numtoken = 1; 23 24 for (int i = 0; i < source.length(); i++) 25 { 26 if (source.charAt(i) == delimiter) 27 numtoken++; 28 } 29 30 String list[] = new String [numtoken]; 31 int nextfield = 0; 32 33 for (int i = 0; i < numtoken; i++) 34 { 35 if (nextfield >= source.length()) 36 { 37 list[i] = ""; 38 } 39 else 40 { 41 int idx = source.indexOf(delimiter, nextfield); 42 if (idx == -1) 43 idx = source.length(); 44 list[i] = source.substring(nextfield, idx); 45 nextfield = idx + 1; 46 } 47 } 48 49 return list; 50 } 51 } 52 | Popular Tags |