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
RarLopzRarLopz 

Escape reserved characters

//Following is string i have in custom setting

Ay|a*s'}+ie'\ }5jI2v[ m);pIB}mnO<qT'?/Abzm*Z+}1#@!l$MdsljF$)b|YZ

//I know I can escape the reserved characters in the string by appeending with \

String mystring =  'Ay|a*s'}+ie<b>\</b>'<b>\</b>\ }5jI2v[ m);pIB}mnO<qT<b>\</b>'?/Abzm*Z+}1#@!l$MdsljF$)b|YZ';

system.debug(mystring);

output exactly as original string: Ay|a*s'}+ie'\ }5jI2v[ m);pIB}mnO<qT'?/Abzm*Z+}1#@!l$MdsljF$)b|YZ

However I don't know how to escape the reserved characters when the string is stored in the custom setting. Everything i have tried has failed.
 
CustomSetting__c cs = CustomSetting__c.getInstance();
 
string afterescapingreservedcharacters = cs.SecretAccessKey__c.unescapeJava();
 
system.debug('After escaping reserved characters:  ' +afterescapingreservedcharacters );


After escaping reserved characters:  Ay|a*s'}+ie' }5jI2v[ m);pIB}mnO<qT'?/Abzm*Z+}1#@!l$MdsljF$)b|YZ

Basically in the out put above the \ is missing from the original string. instead of escaping it, the unEscapeJava funtion removed it.

What do i have to do to escape the reserved characters and get the string as it is in Custom Setting ?