Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to replace all spaces, symbols, numbers, uppercase letters from a string in actionscript?

What would be the best way to simply take a string like

var myString:String = "Thi$ i$ a T#%%Ible Exam73@";

and make myString = "thiiatibleeam";

or another example

var myString:String = "Totally Awesome String";

and make myString = "totallyawesomestring";

In actionscript 3 Thanks!

like image 236
brybam Avatar asked Aug 11 '11 19:08

brybam


1 Answers

Extending @Sam OverMars' answer, you can use a combination of String's replace method with a Regex and String's toLowerCase method to get what you're looking for.

var str:String = "Thi$ i$ a T#%%Ible Exam73@";
str = str.toLowerCase(); //thi$ i$ a t#%%ible exam73@
str = str.replace(/[^a-z]/g,""); //thiiatibleexam

The regular expression means:

[^a-z] -- any character *not* in the range a-z
/g     -- global tag means find all, not just find one
like image 183
Sam DeHaan Avatar answered Oct 06 '22 14:10

Sam DeHaan