如何在AS3中从字符串中删除空格?
我想要删除所有回车、空格、制表符等。
var rex:RegExp = /[\s\r\n]+/gim;
var str:String = "This is a string.";
str = str.replace(rex,'');
// str is now "Thisisastring."
要截取字符串的前后部分,请使用
var rex:RegExp /^\s*|\s*$/gim;
StringUtil.trim(" my string ")
。请参阅此处获取文档。已在AnimateCC iOS air应用程序上测试并正常工作:
// Regular expressions
var spaces:RegExp = / /gi; // match "spaces" in a string
var dashes:RegExp = /-/gi; // match "dashes" in a string
// Sample string with spaces and dashes
loginMC.userName.text = loginMC.userName.text.replace(spaces, ""); // find and replace "spaces"
loginMC.userName.text = loginMC.userName.text.replace(dashes, ":"); // find and replace "dashes"
trace(loginMC.userName.text);
//Tested on Flash CS5 and AIR 2.0
//Regular expressions
var spaces:RegExp = / /gi; // match "spaces" in a string
var dashes:RegExp = /-/gi; // match "dashes" in a string
//Sample string with spaces and dashes
var str:String = "Bu s ~ Tim e - 2-50-00";
str = str.replace(spaces, ""); // find and replace "spaces"
str = str.replace(dashes, ":"); // find and replace "dashes"
trace(str); // output: Bus~Time:2:50:00
^\s*
和\s$
。 - Robusto