How to split a pipe(|), comma(,), tab, space,… separated string in ActionScript 3.0

To split a pipe(|), comma(,), tab, space,…. separated string into multiple string values in ActionScript 3.0, you will have to use the split() method of String class. Below is short example where in a pipe(|) seperated string is broken up into multiple values and pushed into an array.

var cities:String = "Bombay|Los Angeles|Moscow|London|Rio de Janeiro|Sydney";
var citiesArray:Array = cities.split("|");

trace(citiesArray); //Result: Bombay,Los Angeles,Moscow,London,Rio de Janeiro,Sydney
Advertisements
Tagged , ,

3 thoughts on “How to split a pipe(|), comma(,), tab, space,… separated string in ActionScript 3.0

  1. shamna says:

    how to split comma separation in a string in ActionScript

  2. Mihai says:

    Whenever using a delimiter dont use something common such as a comma because a comma can be part of a name and when split it becomes 2 names… which is no intended… always use a very custom delimiter such as
    ~|~
    or

    this way you wont run into this common problem down the road when testing with complex data sets.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Advertisements