chinnusaccount
chinnusaccount

Reputation: 229

How can I replace the word with another in a string?

I have following xml string, In that I need to replace "dddomain1" with "dddomain"

I used the code below, but not working

xmlString.replaceAll("dddomain1","dddomain"); 

Upvotes: 1

Views: 91

Answers (3)

LawsOfNature
LawsOfNature

Reputation: 21

Since String is immutable, replaceAll() returns a new String instead

String newXMLString = xmlString.replaceAll("xpsystems114", "xpsystems");
System.out.println(newXMLString);

Upvotes: 0

Farhan Syed
Farhan Syed

Reputation: 326

Strings are immutable. Any operation on returns a new String. Like @Maroun said, assign the returning reference to a String variable.

Upvotes: 2

Scary Wombat
Scary Wombat

Reputation: 44834

You do not need to use the replaceAll method as this is for regexp.

try

xmlString = xmlString.replace("xpsystems114","xpsystems"); 

Upvotes: 5

Related Questions