+ Start a Discussion
RSKRSK 

How to remove special characters in a Sting

 Hi, I need to remove special characters in a string ?, do we have any apex methods to remove spl characters ? Or any alternate solution ?.

Any help is highly appreciated.

 

Thanks In Advance,

Kumar

kiranmutturukiranmutturu

whats that string ?....

 

 

 

 

regards, 

 

 

Kiran

Ritesh AswaneyRitesh Aswaney

String yourString = 'may the force be with @you^';

String specialChars = '&|^|@';   // in this string, write all the special chars you want to get ride of, pipe separated


for(integer i=0; i<specialChars.split('|').size(); i++)

yourString = yourString.replace(specialChars.split('|')[i], '');

System.debug('Special-chars free string is >>>>>>>>>>>>>>>>>>>>>>>>>>>>> ' + yourString);

RSKRSK

Thanks for your response. 

 

It works like a charm.  But giving spaces between each and every character in the sting.

 

exp:

 

String  :  Jarocinie" Sp. z o.o.

 

Special-chars free string :   J a r o c i n i e     S p     z   o   o

 

 

 

Regards,

Kumar

Anitha J J 2Anitha J J 2
Thank you So much...Our error got resolved ..Thanks to u :) 

By
Anitha