Wednesday, December 26, 2018

How to remove all special characters from String in Apex

This post explains how to remove special characters from the string in Apex
Example:
String strText = 'Welcome - to! % $sale&sforce \\ /code # crack %';
strText = strText.replaceAll('[^a-zA-Z0-9\\s+]', '');
System.debug('strText ======> '+strText);

Result
Happy Learning!!!

1 comment:

  1. How to handle this for all kinds of regional languages as well ? I mean if I want to remove any special characters in any String containing Regional Languages.

    ReplyDelete