1 25 package org.snipsnap.util; 26 27 import java.util.StringTokenizer ; 28 29 35 public class StringUtil { 36 public static String plural(int i, String s1, String s2) { 37 StringBuffer buffer = new StringBuffer (); 38 return plural(buffer, i, s1, s2).toString(); 39 } 40 41 public static String [] split(String string, String delimiter) { 42 StringTokenizer tokenizer = new StringTokenizer (string, delimiter); 44 String [] result = new String [tokenizer.countTokens()]; 45 int i=0; 46 while(tokenizer.hasMoreTokens()) { 47 result[i++] = tokenizer.nextToken(); 48 } 49 return result; 50 } 51 52 public static String plural(int i, String s) { 53 StringBuffer buffer = new StringBuffer (); 54 return plural(buffer, i, s).toString(); 55 } 56 57 public static StringBuffer plural(StringBuffer buffer, int i, String s1, String s2) { 58 buffer.append(i); 59 buffer.append(" "); 60 if (i > 1 || i == 0) { 61 buffer.append(s1); 62 } else { 63 buffer.append(s2); 64 } 65 return buffer; 66 } 67 68 public static StringBuffer plural(StringBuffer buffer, int i, String s) { 69 buffer.append(i); 70 buffer.append(" "); 71 buffer.append(s); 72 if (i > 1 || i == 0) { 73 buffer.append("s"); 74 } 75 return buffer; 76 } 77 } 78 | Popular Tags |