AS支除兩邊的空格

/***************Public Function******************/
function LTrim(str:String):String {
var _s:String = str;
var _len:Number = _s.length;
var _char:String;
var i:Number = -1;
while (++i<_len) {
_char = _s.substr(i, 1);
if (_char != " " && _char != "\n" && _char != "\f" && _char != "\r" && _char != "\t") {
return _s.substr(i, _len-i);
}
}
}

function RTrim(str:String):String {
var _s:String = str;
var _len:Number = _s.length;
var _char:String;
var i:Number = _len;
while (--i>0) {
_char = _s.substr(i, 1);
if (_char != " " && _char != "\n" && _char != "\f" && _char != "\r" && _char != "\t") {
return _s.substr(0, ++i);
}
}
}

function Trim(str:String):String {
return LTrim(RTrim(str));
}

 

posted @ 2012-01-04 14:23  Athrun  阅读(206)  评论(0编辑  收藏  举报