function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Using Replace function did not work????

How would one replace the ampersand in this:

R & S

so in an url for salesforce to pick it up it comes in as:


I tried:

String abc;
abc ='&', '+&+');

That did not work...


I am overriding a URL... 


I just tried this and it worked:


String s = 'R & S'; s=s.replace(' & ', '+&+'); System.debug(s);


 It returned R+&+S



Try this:


encodingUtil.urlEncode(myString, 'UTF-8');




Hi mmaxtra!!

You could use:



When you use /g you are making a global replace so each & that is found in a string will be replaced

See you