chaitu chaitu
asked on
how to replace one specific string in whole string
String namespace = "@{XYZ/1.0}categories:";
String result= "(\"workspace://123456\" AND \"workspace://55757575\")" ;
How to append namespace for every workspace in result string .so final output will be
(@{XYZ/1.0}categories:"wor kspace://1 23456" AND @{XYZ/1.0}categories:"work space://55 757575");
String result= "(\"workspace://123456\" AND \"workspace://55757575\")"
How to append namespace for every workspace in result string .so final output will be
(@{XYZ/1.0}categories:"wor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you really want to use replaceAll (using regex), you can do the following (the search string contains metacharacters so needs quoting)
String nq = "\\Q" + namespace + "\\E";
s = s.replaceAll(nq, namespace + result);
You need to use return value of replaceAll() method. replaceAll() does not replace the characters in the current string, it returns a new string with replacement.
outputs
- String objects are immutable, their values cannot be changed after they are created.
- You may use replace() instead of replaceAll() if you don't need regex.
String str = "abcd=0; efgh=1";
String replacedStr = str.replaceAll("abcd", "dddd");
System.out.println(str);
System.out.println(replacedStr);
outputs
abcd=0; efgh=1
dddd=0; efgh=1
Thanx 4 axxepting
How to append namespace for every workspace in result string .so final output will beHang on - i think i misunderstood. Did you mean how do you PREpend namespace?
ASKER
yes
Open in new window