package com.tienway.util;</p><p>import java.util.ArrayList;</p><p>public class StringUtil<br />{</p><p> public static String ContextType1ToType2(String Type1Context)<br /> {<br /> if (Type1Context== null || Type1Context.length() == 0)<br /> {<br /> return "";<br /> }<br /> char[] c = Type1Context.toCharArray();<br /> StringBuffer sb = new StringBuffer();<br /> for (int i = 0; i < c.length; i++)<br /> {<br /> switch (c[i])<br /> {<br /> case '>':<br /> sb.append(">");<br /> break;<br /> case '<':<br /> sb.append("<");<br /> break;<br /> case ' ':<br /> sb.append(" ");<br /> break;<br /> case '"':<br /> sb.append(""");<br /> break;<br /> case '&':<br /> sb.append("&");<br /> break;<br /> case '/n':<br /> sb.append("<br>");<br /> break;<br /> default:<br /> try<br /> {<br /> sb.append(c[i]);<br /> } catch (Exception ex)<br /> {<br /> }<br /> }<br /> }<br /> return sb.toString();<br /> }</p><p> public static boolean isLetter(char c)<br /> {<br /> int k = 0x80;<br /> return c / k == 0 ? true : false;<br /> }</p><p> public static int length(String s)<br /> {<br /> char[] c = s.toCharArray();<br /> int len = 0;<br /> for (int i = 0; i < c.length; i++)<br /> {<br /> len++;<br /> if (!isLetter(c[i]))<br /> {<br /> len++;<br /> }<br /> }<br /> return len;<br /> }</p><p> public static String replaceAll(String strin, String regex,<br /> String replacement)<br /> {<br /> StringBuffer sb = new StringBuffer();<br /> int rbegin = 0;<br /> int rend = strin.indexOf(regex);<br /> int rlen = regex.length();<br /> while (rend >= 0)<br /> {<br /> sb.append(strin.substring(rbegin, rend));<br /> sb.append(replacement);<br /> rbegin = rend + rlen;<br /> rend = strin.indexOf(regex, rbegin);<br /> }<br /> sb.append(strin.substring(rbegin));<br /> strin = sb.toString();<br /> return strin;<br /> }</p><p> public static String[] split(String strin, char c)<br /> {<br /> return split(strin, c, 0);<br /> }</p><p> public static String[] split(String strin, char c, int it)<br /> {<br /> ArrayList arraylist = new ArrayList();<br /> char[] chark = strin.toCharArray();<br /> StringBuffer sb = new StringBuffer();<br /> for (int i = it; i < chark.length; i++)<br /> {<br /> if (chark[i] == c)<br /> {<br /> arraylist.add(sb.toString());<br /> sb = new StringBuffer();<br /> } else<br /> {<br /> try<br /> {<br /> sb.append(chark[i]);<br /> } catch (Exception e)<br /> {</p><p> }<br /> if (i == chark.length - 1)<br /> {<br /> arraylist.add(sb.toString());<br /> }<br /> }<br /> }</p><p> int k = arraylist.size();<br /> String as[] = new String[k];<br /> return (String[]) arraylist.subList(0, k).toArray(as);<br /> }</p><p> public static String[] split(String strin, String c)<br /> {<br /> if (strin == null)<br /> {<br /> return null;<br /> }</p><p> ArrayList arraylist = new ArrayList();<br /> int begin = 0;<br /> int end = 0;<br /> while ((begin = strin.indexOf(c, end)) != -1)<br /> {<br /> String s2 = strin.substring(end, begin);</p><p> {<br /> arraylist.add(strin.substring(end, begin));<br /> }<br /> end = begin + c.length();<br /> }<br /> if (end != strin.length())<br /> {<br /> arraylist.add(strin.substring(end));<br /> }</p><p> int k = arraylist.size();<br /> String as[] = new String[k];<br /> return (String[]) arraylist.subList(0, k).toArray(as);<br /> }</p><p> public static String toBin(char c)<br /> {<br /> int k = 0x8000;<br /> StringBuffer sb = new StringBuffer(16);<br /> for (int i = 0; i < 16; k >>>= 1, i++)<br /> {<br /> sb.append(((c & k) != 0) ? 1 : 0);<br /> }<br /> return sb.toString();<br /> }</p><p>}