1 20 package org.objectweb.modfact.corba.helper; 21 22 import java.util.StringTokenizer ; 23 24 27 public class StringHelper { 28 29 36 public static String replaceFirst(String original, String to_replace, String new_value) { 37 int index = original.indexOf(to_replace); 38 if (index != -1) { 39 return original.substring(0, index) + new_value + original.substring(index+to_replace.length()); 40 } else { 41 return original; 42 } 43 } 44 45 52 public static String replaceAll(String original, String to_replace, String new_value) { 53 StringBuffer newString = new StringBuffer (); 54 int indexBegin = 0; 55 int index = original.indexOf(to_replace, indexBegin); 56 while (index != -1) { 57 newString.append(original.substring(indexBegin, index)); 58 newString.append(new_value); 59 indexBegin = index + to_replace.length(); 60 index = original.indexOf(to_replace, indexBegin); 61 } 62 newString.append(original.substring(indexBegin)); 63 return newString.toString(); 64 } 65 66 73 public static boolean matchesValues(String to_parse, String value) { 74 StringTokenizer token = new StringTokenizer (value, "|"); 75 while (token.hasMoreTokens()) { 76 if (to_parse.equals(token.nextToken())) 77 return true; 78 } 79 return false; 80 } 81 82 89 public static boolean endsWithValues(String to_parse, String value) { 90 StringTokenizer token = new StringTokenizer (value, "|"); 91 while (token.hasMoreTokens()) { 92 if (to_parse.endsWith(token.nextToken())) 93 return true; 94 } 95 return false; 96 } 97 98 } 99 | Popular Tags |