1 18 package sync4j.exchange.util; 19 20 import java.util.StringTokenizer ; 21 22 28 public class StringTools { 29 30 37 public static String [] split(String s) { 38 StringTokenizer st = new StringTokenizer (s, ", "); 39 40 String [] values = new String [st.countTokens()]; 41 42 for (int i=0; i<values.length; ++i) { 43 values[i] = st.nextToken(); 44 } 45 46 return values; 47 } 48 49 56 public static String join(String [] array) { 57 StringBuffer sb = new StringBuffer (); 58 for (int i=0; (i<array.length); ++i) { 59 if (i == 0) { 60 sb.append(array[i]); 61 } else { 62 sb.append(',').append(array[i]); 63 } 64 } 65 66 return sb.toString(); 67 } 68 69 76 public static boolean isEmpty(String s) { 77 return (s == null) || (s.length() == 0); 78 } 79 80 87 public static String replaceSpecial(String s) { 88 String ret = new String (s); 89 90 char[] chars = s.toCharArray(); 91 for (int i=0; i < chars.length; ++i) { 92 if ((chars[i] < '0' || chars[i] > '9') && 93 (chars[i] < 'a' || chars[i] > 'z') && 94 (chars[i] < 'A' || chars[i] > 'Z')) { 95 chars[i] = '_'; 96 } 97 } 98 99 return new String (chars); 100 } 101 102 103 114 public static String escapeXml(String str) { 115 if (str == null) { 116 return null; 117 } 118 119 if (str != null) { 120 return Entities.XML.escape(str); 121 } else { 122 return null; 123 } 124 } 125 126 138 public static String unescapeXml(String str) { 139 if (str == null) { 140 return null; 141 } 142 return Entities.XML.unescape(str); 143 } 144 145 146 } | Popular Tags |