Question: In java how to replace string between 2 character? Example I am given a string, String test = address {address} address2 {address2} I want to
In java how to replace string between 2 character?
Example I am given a string,
String test = "address {address} address2 {address2}"
I want to be able to replace the address between brackets{} to "123 test street" ans address2 between brackets {} to "123 abc street".
Therefore I want the output to be "address 123 test street address2 123 abc street".
I have tried following,
test = test.replace("address", "123 test street")
and
test = test.replace("address2", "123 abc street")
These does not work as I have not specified brackets in anywhere in code and also when I replace the "address", it is also replacing the address in "address2" with the value of address (123 test street), since I have specified address first.
Is there a way I could tell program to change the address and address2 between the brackets only and also not to change "address" in "address2" with the value of address?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
