You need to sign in to do that
Don't have an account?

how to remove special character like \\ in apex?
Hey I am a beginner I don't know how to solve this please help me
For this array:-
[{\\"stage\\":\\"10 - Application\\",\\"oppId\\":\\"2dwd23d231d2w\\",\\"message\\":\\"Opportunity status created.\\"},{\\"stage\\":closedwon,\\"oppId\\":\\"2dwd23d231d2w\\",\\"message\\":\\"Opportunity not found or permission denied.\\"}]
For this array:-
[{\\"stage\\":\\"10 - Application\\",\\"oppId\\":\\"2dwd23d231d2w\\",\\"message\\":\\"Opportunity status created.\\"},{\\"stage\\":closedwon,\\"oppId\\":\\"2dwd23d231d2w\\",\\"message\\":\\"Opportunity not found or permission denied.\\"}]
Below code works fine please check this out:-
String source = '"[{\\"stage\\":\\"10 - Application\\",\\"oppId\\":\\"2dwd23d231d2w\\",\\"message\\":\\"Opportunity status created.\\"},{\\"stage\\":closedwon,\\"oppId\\":\\"2dwd23d231d2w\\",\\"message\\":\\"Opportunity not found or permission denied.\\"}]"';
String decodedJson = (String)JSON.deserialize(source, String.class);
System.debug('DecodedJson>>>'+decodedJson);
Hope this explanation will resolve your query. Mark it as the best answer if you find it helpful.
Thanks
Akshay
All Answers
Below is the sample snippet.
References:
https://salesforce.stackexchange.com/questions/169773/apex-regex-to-remove-the-special-character/169774#:~:text=2%20Answers&text=replaceAll('%5C%5CD',digit%20from%20the%20phone%20number.
https://www.biswajeetsamal.com/blog/remove-all-special-characters-from-string-in-apex/
Hope this helps...
Thanks,
Below code works fine please check this out:-
String source = '"[{\\"stage\\":\\"10 - Application\\",\\"oppId\\":\\"2dwd23d231d2w\\",\\"message\\":\\"Opportunity status created.\\"},{\\"stage\\":closedwon,\\"oppId\\":\\"2dwd23d231d2w\\",\\"message\\":\\"Opportunity not found or permission denied.\\"}]"';
String decodedJson = (String)JSON.deserialize(source, String.class);
System.debug('DecodedJson>>>'+decodedJson);
Hope this explanation will resolve your query. Mark it as the best answer if you find it helpful.
Thanks
Akshay
There are different ways to remove special characters you can remove all special characters and also remove particular characters.
To remove all characters use: -
String name = '{B]@i%s*w:?,-a$j#e)e(t! S^a.m}a]l[';
name = name.replaceAll('[^a-zA-Z0-9\\s+]', '');
system.debug(name);
To relace particular character:-
String str='Rohit & Mohit';
String str2=str.replace('&','and');
System.debug(str2);