我试图分开一个字符串的两个部分,一个是标题一个是Value,RegExp让我困惑。我需要你的帮助来解决这个问题
var pattern2:RegExp = new RegExp("TZ_NUM_ANSWER:Telegram code([0-9.-]+)");//TZ_NUM_ANSWER:Telegram code 32263
var data2:Object = pattern2.exec(response);
if (data2 != null && data2[1] != null)
{
var value2:Number = parseFloat(data2[1]);
trace("TZ_NUM_ANSWER " + value2);
txt_BUY1.text = String(value2);
}
输出:
TZ_NUM_ANSWER:Telegram code 32263
必须是:
"TZ_NUM_ANSWER:" "Telegram code 32263"
答案 0 :(得分:1)
split 的结果是数组,您可以访问数组 索引并将它们分配给变量
var STR1:String = "TZ_NUM_ANSWER:Telegram code 32263";
var STR2:String;
var STR3:String;
trace(STR1.split(":"));
STR2 = STR1.split(":")[0];
STR3 = STR1.split(":")[1];
trace (STR2);
trace (STR3);
结果:
TZ_NUM_ANSWER
Telegram code 32263
答案 1 :(得分:0)
不要将RegEx用于简单的东西。您只需要基本的字符串方法:
response.split(":");