Replace all spaces, symbols, numbers, uppercase letters in ActionScript?

What is the best way to simply use strings

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”;

Thank you in action 3!

To expand on @Sam OverMars’s answer, you can combine the replace method of String with Regex and String’s toLowerCase method to get what you want.

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

Regular expression means:

[^az] - any character *not* in the range az
/g - global tag means find all, not just find one

What is the best way to simply use strings

 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”;

Thank you in action 3!

Extending the answer of @Sam OverMars, you can combine String’s replace method with Regex and String’s toLowerCase method to get what you want.

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

Regular expression means:

[^az] - any character *not* in the range az
/g - global tag means find all, not just find one

< /p>

Leave a Comment

Your email address will not be published.