List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:Main.java
/** * remove from a name any characters not allowed in XML tags * (what are they?)/*from w ww . j a va2 s . c om*/ * @param name * @return */ public static String legalTagName(String name) { String tagName = ""; StringTokenizer st = new StringTokenizer(name, " ,/;'\\"); while (st.hasMoreTokens()) tagName = tagName + st.nextToken(); return tagName; }
From source file:Main.java
public static void addDepsFromCSL(Set<String> deps, String dep) { if (dep != null) { StringTokenizer tk = new StringTokenizer(dep, ","); while (tk.hasMoreTokens()) { String d = tk.nextToken().trim(); if (d.length() > 0) { deps.add(d);//w w w. j av a2 s . c om } } } }
From source file:Main.java
public static String titleCase(String s) { StringBuilder rv = new StringBuilder(s.length()); StringTokenizer strtok = new StringTokenizer(s); while (strtok.hasMoreTokens()) { String word = strtok.nextToken(); String firstLetter = word.substring(0, 1); String restOfWord = word.substring(1); if (rv.length() > 0) rv.append(" "); rv.append(firstLetter.toUpperCase()); rv.append(restOfWord.toLowerCase()); }//w w w. j a va2 s . co m return rv.toString(); }
From source file:Main.java
public static int stringIPtoInt(String ip) { StringTokenizer ipTokens = new StringTokenizer(ip, "."); int ipArray[] = new int[4]; ipArray[0] = Integer.parseInt(ipTokens.nextToken()); ipArray[1] = Integer.parseInt(ipTokens.nextToken()); ipArray[2] = Integer.parseInt(ipTokens.nextToken()); ipArray[3] = Integer.parseInt(ipTokens.nextToken()); return (ipArray[0] << 24) + (ipArray[1] << 16) + (ipArray[2] << 8) + ipArray[3]; }
From source file:com.sonatype.nexus.perftest.RequestRate.java
private static int parseRate(String value) { StringTokenizer st = new StringTokenizer(value, " /"); int time = Integer.parseInt(st.nextToken()); TimeUnit unit = TimeUnit.valueOf(st.nextToken() + "S"); return (int) (unit.toMillis(1) / time); }
From source file:Main.java
/** * Remove leading a trailing whitespace characters from each line of input * @param input/* w w w . j a v a 2 s .c o m*/ * @return */ public static String trim(String input) { final String newlineDelimiters = "\n\r\f"; StringBuilder ret = new StringBuilder(); StringTokenizer st = new StringTokenizer(input, newlineDelimiters); while (st.hasMoreTokens()) { ret.append(st.nextToken().replaceAll("^\\s+", "").replaceAll("\\s+$", "")); ret.append('\n'); } return ret.toString(); }
From source file:StringUtil.java
/** * replaces all newlines in the given String 's' with the replacement * string 'r'. Each line is trimmed from leading and trailing whitespaces, * then the new line-delimiter is added. * * @param s the source string.//from ww w . jav a2 s. c om * @param r the new line delimiter * @return the resulting string. */ public static final String replaceNewLines(String s, String r) { StringBuilder result = new StringBuilder(); StringTokenizer t = new StringTokenizer(s, "\n"); while (t.hasMoreTokens()) { result.append(t.nextToken().trim()).append(r); } return result.toString(); }
From source file:Main.java
public static List<String> parseStringList(String l, String separator) { List<String> tmp = new LinkedList<String>(); StringTokenizer tok = new StringTokenizer(l, separator); String t;/*from ww w . j a va2s. c om*/ while (tok.hasMoreTokens()) { t = tok.nextToken(); tmp.add(t.trim()); } return tmp; }
From source file:Main.java
private static List<String> stringToArray(String str) { try {// ww w . j a v a 2 s . c om List<String> arg = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(str, ","); while (st.hasMoreTokens()) { arg.add(st.nextToken()); } return arg; } catch (Exception e) { return null; } }
From source file:Main.java
public static ArrayList<String> getInput() { ArrayList<String> result = new ArrayList<String>(10); String line;// w w w . j a v a2 s.c om try { line = new BufferedReader(new InputStreamReader(System.in)).readLine(); if (line != null) { StringTokenizer st = new StringTokenizer(line); while (st.hasMoreTokens()) result.add(st.nextToken()); } } catch (IOException e) { e.printStackTrace(); } return result; }