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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started