@Test public void replace_EmptyReplacementString_RemovesAllOccurencesOfMatchString() { assertEquals("bbb", StringUtils.replace("ababab", "a", "")); }
public static String replace( String originalString, String partToMatch, String replacement ) { StringBuilder buffer = new StringBuilder( originalString.length() ); buffer.append( originalString ); int indexOf = buffer.indexOf( partToMatch ); while (indexOf != -1) { buffer = buffer.replace(indexOf, indexOf + partToMatch.length(), replacement); indexOf = buffer.indexOf(partToMatch, indexOf + replacement.length()); } return buffer.toString(); }
StringUtils { public static String replace( String originalString, String partToMatch, String replacement ) { StringBuilder buffer = new StringBuilder( originalString.length() ); buffer.append( originalString ); int indexOf = buffer.indexOf( partToMatch ); while (indexOf != -1) { buffer = buffer.replace(indexOf, indexOf + partToMatch.length(), replacement); indexOf = buffer.indexOf(partToMatch, indexOf + replacement.length()); } return buffer.toString(); } }
StringUtils { public static String replace( String originalString, String partToMatch, String replacement ) { StringBuilder buffer = new StringBuilder( originalString.length() ); buffer.append( originalString ); int indexOf = buffer.indexOf( partToMatch ); while (indexOf != -1) { buffer = buffer.replace(indexOf, indexOf + partToMatch.length(), replacement); indexOf = buffer.indexOf(partToMatch, indexOf + replacement.length()); } return buffer.toString(); }  }
StringUtils { public static String replace( String originalString, String partToMatch, String replacement ) { StringBuilder buffer = new StringBuilder( originalString.length() ); buffer.append( originalString ); int indexOf = buffer.indexOf( partToMatch ); while (indexOf != -1) { buffer = buffer.replace(indexOf, indexOf + partToMatch.length(), replacement); indexOf = buffer.indexOf(partToMatch, indexOf + replacement.length()); } return buffer.toString(); }  static Integer toInteger(StringBuilder value); static String toString(StringBuilder value); static Boolean toBoolean(StringBuilder value); static String fromInteger(Integer value); static String fromLong(Long value); static String fromString(String value); static String fromBoolean(Boolean value); static String fromBigInteger(BigInteger value); static String fromBigDecimal(BigDecimal value); static BigInteger toBigInteger(String s); static BigDecimal toBigDecimal(String s); static String fromFloat(Float value); static String fromDate(Date value); static String fromDouble(Double d); static String fromByte(Byte b); static String fromByteBuffer(ByteBuffer byteBuffer); static String replace( String originalString, String partToMatch, String replacement ); static String join(String joiner, String... parts); static String trim(String value); static boolean isNullOrEmpty(String value); static boolean hasValue(String str); static String lowerCase(String str); static String upperCase(String str); static int compare(String str1, String str2); static void appendCompactedString(final StringBuilder destination, final String source); static boolean beginsWithIgnoreCase(final String data, final String seq); static Character findFirstOccurrence(String s, char ...charsToMatch); }
StringUtils { public static String replace( String originalString, String partToMatch, String replacement ) { StringBuilder buffer = new StringBuilder( originalString.length() ); buffer.append( originalString ); int indexOf = buffer.indexOf( partToMatch ); while (indexOf != -1) { buffer = buffer.replace(indexOf, indexOf + partToMatch.length(), replacement); indexOf = buffer.indexOf(partToMatch, indexOf + replacement.length()); } return buffer.toString(); }  static Integer toInteger(StringBuilder value); static String toString(StringBuilder value); static Boolean toBoolean(StringBuilder value); static String fromInteger(Integer value); static String fromLong(Long value); static String fromString(String value); static String fromBoolean(Boolean value); static String fromBigInteger(BigInteger value); static String fromBigDecimal(BigDecimal value); static BigInteger toBigInteger(String s); static BigDecimal toBigDecimal(String s); static String fromFloat(Float value); static String fromDate(Date value); static String fromDouble(Double d); static String fromByte(Byte b); static String fromByteBuffer(ByteBuffer byteBuffer); static String replace( String originalString, String partToMatch, String replacement ); static String join(String joiner, String... parts); static String trim(String value); static boolean isNullOrEmpty(String value); static boolean hasValue(String str); static String lowerCase(String str); static String upperCase(String str); static int compare(String str1, String str2); static void appendCompactedString(final StringBuilder destination, final String source); static boolean beginsWithIgnoreCase(final String data, final String seq); static Character findFirstOccurrence(String s, char ...charsToMatch); static final String COMMA_SEPARATOR; static final Charset UTF8; }