1

I am sending an Http request who's body contains XML payload. Data sent over can have apostrophes which causes my palyload to error out. XML payload looks something like

<comments>testString</Ccomments>

where testString is a string variable that contains apostrophes.

I tried using

 string.escapeSingleQuotes(testString);

but this replaces ' with \'

I want to replace all apostrophes with &apos;

Any suggestions?

1
  • How about a = a.replace('\'', '&apos;'); Commented Jun 26, 2013 at 15:24

2 Answers 2

3

You can use the escapeHtml4 String method.

String s1 = 
   '"<Black&White>"';
String s2 = 
   s1.escapeHtml4();
System.debug(s2);
// Output:
// &quot;&lt;Black&amp;
// White&gt;&quot;
1

Use EncodingUtil.urlEncode(); it worked for me. http://www.salesforce.com/us/developer/docs/dbcom_apex250/Content/apex_classes_restful_encodingUtil.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .