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
mmaxtrammaxtra 

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:

R+&+S

I tried:

String abc;
abc = c.name.replace('&', '+&+');

That did not work...

 

I am overriding a URL... 

asadim2asadim2

I just tried this and it worked:

 

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

 

 It returned R+&+S

 

XactiumBenXactiumBen

Try this:

 

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

 

MayeUPAEPMayeUPAEP

 


Hi mmaxtra!!

You could use:

abc=c.replace(/&/g,'+&+'); 

 

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

See you