Link to home
Start Free TrialLog in
Avatar of alfredng1
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!
Avatar of RishadanPort
RishadanPort

const string varToRemove = "you";
const string varToRemove2 = "You";
const string varToReplace = "Jack Bauer";

string.replace(varToRemove, varToReplace);

string.replace(varToRemove2, varToReplace);
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);
Same solution at the same time ;)
ID:22619880Author:RishadanPortDate:10.02.2008 at 04:23AM IST
ID:22619881Author:basav_comDate:10.02.2008 at 04:23AM IST

SOLUTION
Avatar of verickson
verickson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Checked with Eclipse and QuickREx by the way, use the right tool for the right job.