我有这样的变量#aa0000
如何删除AA55BBB(888)1234567890P1
和)
之间的字符?
答案 0 :(得分:0)
通常你用正则表达式来做,但AS2不支持它们。所以另一个(老式的)解决方案是将这些字符上的字符串拆分并再次加入
这假设您只有一个")"和一个" P"在你的字符串中:
var myString:String = "AA55BBB(888)1234567890P1";
// this will result in an Array like ["AA55BBB(888", "1234567890P1"];
var firstSplit:Array = myString.split(")");
var firstPart:String = firstSplit[0]; // "AA55BBB(888"
var secondPart:String = firstSplit[1]; // "1234567890P1"
var secondSplit:Array = secondPart.split("P"); // ["1234567890","1"]
secondPart = secondSplit[1]; //"1"
// since we have removed the ")" and "P" on split, put them back in
var newString:String = firstPart + ")P" + secondPart;
trace(newString); // "AA55BBB(888)P1"