@Test public void testReplace() { assertEquals(null, StringUtils.replace(null, null, null)); assertEquals("", StringUtils.replace("", null, null)); assertEquals("test null test", StringUtils.replace("test null test", null, "")); assertEquals("test test", StringUtils.replace("test a test", "a", null)); assertEquals("test test", StringUtils.replace("test test", "", "oops")); assertEquals("test test", StringUtils.replaceAll("test test", null, "oops")); assertEquals("testoopsoopstest", StringUtils.replace("test test", " ", "oops")); assertEquals("1-two-3", StringUtils.replace("1 2 3", " 2 ", "-two-")); }
public static String replace(String source, String find, String replace) { if (source == null || find == null || find.length()==0) return source; int index = source.indexOf(find); if (index < 0) return source; if (replace==null) replace=""; int len = find.length(); return source.substring(0,index) + replace + replace(source.substring(index+len), find, replace); }
StringUtils { public static String replace(String source, String find, String replace) { if (source == null || find == null || find.length()==0) return source; int index = source.indexOf(find); if (index < 0) return source; if (replace==null) replace=""; int len = find.length(); return source.substring(0,index) + replace + replace(source.substring(index+len), find, replace); } }
StringUtils { public static String replace(String source, String find, String replace) { if (source == null || find == null || find.length()==0) return source; int index = source.indexOf(find); if (index < 0) return source; if (replace==null) replace=""; int len = find.length(); return source.substring(0,index) + replace + replace(source.substring(index+len), find, replace); } private  StringUtils(); }
StringUtils { public static String replace(String source, String find, String replace) { if (source == null || find == null || find.length()==0) return source; int index = source.indexOf(find); if (index < 0) return source; if (replace==null) replace=""; int len = find.length(); return source.substring(0,index) + replace + replace(source.substring(index+len), find, replace); } private  StringUtils(); static String toString(Object value, String defValue); static String toString(Object value); static String toString(Object[] array, String defValue); static String toString(Object[] array); static String valueOf(Object value); static String valueOf(Object[] array); static String coalesce(String preferred, String alternative); static String nullIfEmpty(Object value); static boolean contains(String value, String substring); static boolean notContains(String value, String substring); static String arrayToString(Object[] array, String separator); static boolean isEmpty(String s); static boolean isNotEmpty(String s); static boolean compareEqual(String s1, String s2, boolean ignoreCase); static boolean compareEqual(String s1, String s2); static boolean compareNotEqual(String s1, String s2, boolean ignoreCase); static boolean compareNotEqual(String s1, String s2); static String validate(String s); static String replace(String source, String find, String replace); static String replaceAll(String s, String find, String replace); static String remove(String s, String remove); static String remove(String s, char c); static String removeBlanks(String s); static boolean isCharBetween(char c, char beg, char end); static boolean isNumber(char c); static boolean isNumber(String s); static boolean isNumeric(char c, boolean decimal); static boolean isNumeric(String s, boolean decimal); static boolean isUpper(char c); static boolean isUpper(String s, int count); static boolean isLower(char c); static boolean isLower(String s, int count); static String toUpper(String s, int count); static String toLower(String s, int count); }
StringUtils { public static String replace(String source, String find, String replace) { if (source == null || find == null || find.length()==0) return source; int index = source.indexOf(find); if (index < 0) return source; if (replace==null) replace=""; int len = find.length(); return source.substring(0,index) + replace + replace(source.substring(index+len), find, replace); } private  StringUtils(); static String toString(Object value, String defValue); static String toString(Object value); static String toString(Object[] array, String defValue); static String toString(Object[] array); static String valueOf(Object value); static String valueOf(Object[] array); static String coalesce(String preferred, String alternative); static String nullIfEmpty(Object value); static boolean contains(String value, String substring); static boolean notContains(String value, String substring); static String arrayToString(Object[] array, String separator); static boolean isEmpty(String s); static boolean isNotEmpty(String s); static boolean compareEqual(String s1, String s2, boolean ignoreCase); static boolean compareEqual(String s1, String s2); static boolean compareNotEqual(String s1, String s2, boolean ignoreCase); static boolean compareNotEqual(String s1, String s2); static String validate(String s); static String replace(String source, String find, String replace); static String replaceAll(String s, String find, String replace); static String remove(String s, String remove); static String remove(String s, char c); static String removeBlanks(String s); static boolean isCharBetween(char c, char beg, char end); static boolean isNumber(char c); static boolean isNumber(String s); static boolean isNumeric(char c, boolean decimal); static boolean isNumeric(String s, boolean decimal); static boolean isUpper(char c); static boolean isUpper(String s, int count); static boolean isLower(char c); static boolean isLower(String s, int count); static String toUpper(String s, int count); static String toLower(String s, int count);  }