String.split()方法
Array.join()方法
※ 目的是要把 var souceStr:String = "011+886+2+2737-9999"; 這裡的電話號碼字串中的"+"和"-"去除掉
package {
import flash.display.MovieClip;
public class StringSplitArrayJoin_1000525 extends MovieClip {
public function StringSplitArrayJoin_1000525() {
var souceStr:String = "011+886+2+2737-9999";
var specialChars:Array = new Array("+","-");
var newStr:String = this.charsHandler(souceStr,specialChars);
var newNumber = new Number(newStr);
trace("newNumber : " + newNumber); //newNumber : 11886227379999
return;
}
public function charsHandler(_souceStr:String,_specialChars:Array):String{
var _newStr:String = _souceStr;
var arrLength:int = _specialChars.length;
for(var i:int=0; i < arrLength; i++){
_newStr = _newStr.split(_specialChars[i]).join("");
}
return _newStr;
}
}
}
沒有留言:
張貼留言