+ Start a Discussion
SandrineSandrine 

Get a 10 letter alphabets from a text area

Hello,

I want get the first 0 first characters fromtthe text area
I want to replace the following
=> remove space
=> remove special charaters
In short i want to create only create a 10 letters only from alphabts A to Z, 

thanks you for suggestion
 
Best Answer chosen by Sandrine
DeepakSinghDeepakSingh
Hi 
Sandrine,
You can use the following code to get the aspected result.
String strText = 'Welcome - to! % $sale&sforce \\ /code # crack %';
strText = strText.replaceAll('[^a-zA-Z0-9\\s+]', '');
strText= strText.replaceAll( '\\s+', '');
strText = strText.substring(0,10);
System.debug(strText);

Please mark this as resolve nad best answer if it helps you.
Thanks.
Deepak.

All Answers

DeepakSinghDeepakSingh
Hi 
Sandrine,
You can use the following code to get the aspected result.
String strText = 'Welcome - to! % $sale&sforce \\ /code # crack %';
strText = strText.replaceAll('[^a-zA-Z0-9\\s+]', '');
strText= strText.replaceAll( '\\s+', '');
strText = strText.substring(0,10);
System.debug(strText);

Please mark this as resolve nad best answer if it helps you.
Thanks.
Deepak.
This was selected as the best answer
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

To remove all special characters from string in apex you can use:
SomeText.replaceAll('[^a-zA-Z0-9\\s+]', '');

To remove white spaces you can use deleteWhitespace() method:
SomeText.deleteWhitespace();

Try below code in 'Open Execute Anonymous Window':
String name = '{K]@h%a*n:?,-A$n#a)s(T! e^s.t}ting]l[';
name = name.replaceAll('[^a-zA-Z0-9\\s+]', '');
name = name.deleteWhitespace();
name = name.substring(0,10);
System.debug(name);

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas