1 11 package org.eclipse.ui.internal.intro.impl.util; 12 13 import java.io.UnsupportedEncodingException ; 14 import java.lang.reflect.Method ; 15 import java.net.URLDecoder ; 16 import java.util.ArrayList ; 17 import java.util.List ; 18 import java.util.StringTokenizer ; 19 20 21 22 public class StringUtil { 23 24 public static StringBuffer concat(String string1, String string2, 25 String string3) { 26 StringBuffer buffer = new StringBuffer (string1); 27 buffer.append(string2); 28 buffer.append(string3); 29 return buffer; 30 } 31 32 public static StringBuffer concat(String string1, String string2, 33 String string3, String string4) { 34 StringBuffer buffer = concat(string1, string2, string3); 35 buffer.append(string4); 36 return buffer; 37 } 38 39 public static StringBuffer concat(String string1, String string2, 40 String string3, String string4, String string5) { 41 StringBuffer buffer = concat(string1, string2, string3, string4); 42 buffer.append(string5); 43 return buffer; 44 } 45 46 public static StringBuffer concat(String string1, String string2, 47 String string3, String string4, String string5, String string6) { 48 StringBuffer buffer = concat(string1, string2, string3, string4, 49 string5); 50 buffer.append(string6); 51 return buffer; 52 } 53 54 58 public static String [] split(String string, String delimiters) { 59 try { 60 return string.split(delimiters); 61 } catch (NoSuchMethodError e) { 62 List result = new ArrayList (); 64 for (StringTokenizer tokenizer = new StringTokenizer (string, delimiters); tokenizer.hasMoreTokens(); ) 65 result.add(tokenizer.nextToken()); 66 return (String []) result.toArray(new String [result.size()]); 67 } 68 } 69 70 74 public static String decode(String s, String enc) throws UnsupportedEncodingException { 75 try { 76 return URLDecoder.decode(s, enc); 77 } catch (NoSuchMethodError e) { 78 try { 80 Method m = URLDecoder .class.getMethod("decode", new Class [] { String .class }); return (String )m.invoke(null, new Object [] {s}); 83 } 84 catch (Exception ex) { 85 return s; 87 } 88 } 89 } 90 91 } 92 | Popular Tags |