1

I'm trying to separate two part of a string, one is Title one is Value, RegExp is confused me. I need your help to solve this thanks

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);
       }

Output:

TZ_NUM_ANSWER:Telegram code 32263

It must be:

"TZ_NUM_ANSWER:" "Telegram code 32263"
2
  • Is there a reason why you didn't try split? Commented Feb 6, 2017 at 20:30
  • The reason is because I'm new developer. Commented Feb 7, 2017 at 9:51

2 Answers 2

1

The result of split is an Array you can access to Array indexes and assign them to a variable.

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);

Result:

TZ_NUM_ANSWER
Telegram code 32263
Sign up to request clarification or add additional context in comments.

Comments

0

Don't use RegEx for simple stuff. All you need is basic string methods:

response.split(":");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.