1、trim方法,调用leftTrim和rigthTrim
public static function trim(s:String):String{
return leftTrim(rightTrim(s));
}
2、leftTrim方法,取除左边 空格
public static function leftTrim(s:String):String{
var i:Number=0;
while(s.charCodeAt(i)==32
|| s.charCodeAt(i)==13
|| s.charCodeAt(i)==10
|| s.charCodeAt(i)==9
|| s.charCodeAt(i)==0){
i++;
}
return s.substring(i,s.length);
}
3、去除右边空格
public static function rightTrim(s:String):String{
var i:Number=s.length-1;
while(s.charCodeAt(i)==32
|| s.charCodeAt(i)==13
|| s.charCodeAt(i)==10
||s.charCodeAt(i)==9
|| s.charCodeAt(i)==0){
i--;
}
return s.substring(0,i+1);
}
对于上述charCodeAt得到的为ascll码,码表如下:
http://wenku.baidu.com/view/c7a1533131126edb6f1a10a9.html