-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

2

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Oops, my bad. Edited.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.