问题
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!
回答1:
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
回答2:
I think this is the regex you're looking for:
[Bindable]
var myString:String = "Thi$ i$ a T#%%Ible Exam73@";
[Bindable]
var anotherString:String = "";
protected function someFunction():void
{
anotherString = myString.replace(/[^a-zA-Z]/g, "");
anotherString = anotherString.toLowerCase();
}
回答3:
I belive what your looking for is:
var myString = str.replace("find", "replace");
or in your case:
str.replace("$", "");
also, it might be:
str.replace('$', ' ');
//EDIT How about:
var mySearch:RegExp = /(\t|\n|\s{1,})/g;
var myString = str.replace(mySearch, "");
来源:https://stackoverflow.com/questions/7031341/best-way-to-replace-all-spaces-symbols-numbers-uppercase-letters-from-a-strin