alfredng1
asked on
Java substring replacement
I am looking for a good method for doing substring replacement.
For example, the string is "Experts collaborate with you to find solutions! Make their job easier by clearly describing your issue with specific information." and I want to replace the substring "you" to let say "Jack Bauer". I was wondering which method is the best! Please show code example! Thanks!
For example, the string is "Experts collaborate with you to find solutions! Make their job easier by clearly describing your issue with specific information." and I want to replace the substring "you" to let say "Jack Bauer". I was wondering which method is the best! Please show code example! Thanks!
You need to use 'replace' method of String.
Here is the example:
String str="How are you";
str = str.replace("you","John");
System.out.println(str);
Here is the example:
String str="How are you";
str = str.replace("you","John");
System.out.println(str);
Same solution at the same time ;)
ID:22619880Author:Rishadan PortDate:1 0.02.2008 at 04:23AM IST
ID:22619881Author:basav_co mDate:10.0 2.2008 at 04:23AM IST
ID:22619880Author:Rishadan
ID:22619881Author:basav_co
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Checked with Eclipse and QuickREx by the way, use the right tool for the right job.
const string varToRemove2 = "You";
const string varToReplace = "Jack Bauer";
string.replace(varToRemove
string.replace(varToRemove