-1

I have this section of code

String string = "somestring";
String str2 = "str";
String str3 = "xxx"

if ( string.match("(.*)" + str2 + "(.*)") ) {
 // 
}

result = somxxxing

how can i replace that section of string with str3? i need this to work for every strings

1 Answers1

2

Check out the javadoc for java.lang.String.

You're probably looking for String.replace(CharSequence target, CharSequence replacement), which replaces every occurrence of target with replacement.

e.g.

result = string.replace(str2, str3);
sisyphus
  • 6,174
  • 1
  • 25
  • 35