2

I need code sample to separate a string, i'm new developer please write sample code. thanks.

This is string:

[email protected]|3.705|18|0.90

I need to separate each part between "|":

[email protected]

3.705

18

0.90

2 Answers 2

1
var Sample_String: String = "[email protected]|3.705|18|0.90"

var VALUE1: String = Sample_String.split("|")[0];
var VALUE2: String = Sample_String.split("|")[1];
var VALUE3: String = Sample_String.split("|")[2];
var VALUE4: String = Sample_String.split("|")[3];

trace(VALUE1);
trace(VALUE2);
trace(VALUE3);
trace(VALUE4);

//--------------------------------------------------------------------------- Output:

[email protected]
3.705
18
0.90
Sign up to request clarification or add additional context in comments.

1 Comment

Bad in terms of performance. String.split(...) is relatively heavy operation and it is much better to do it only once and assign the resulting Array to a temporary variable.
1

You can use split function once to create an Array of split String as below:

private var myString:String = "[email protected]|3.705|18|0.90";

var splitStringArray: Array = myString.split("|");
for each (var splitString:String in splitStringArray)
{
    trace(splitString);
}

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.