Subscribe

  • Subscribe  

How to Split Strings in AS3

Posted by Jay | April 21, 2008 .

Well… as I had mentioned in one of my earlier posts, I am basically a Java programmer and hence when it comes to programming in ActionScript, I realize that the bits of code that I take for granted in Java are things I need to ponder about a little when they are to be coded in AS3. One such challenge was splitting strings. Now, in hindsight, it sounds so simple; however, at that time, I spent a good three hours in trying to figure this out. And, at the end of my three hours of frantic syntax searching and racking out my brains, I discovered the split() function in AS3. Here’s how to use this function.

The syntax for this function is: split(delimiter:String, [limit:Number]) : Array. The first parameter—delimiter:String—would be the string or character at which I want to split a string called my_string, and the second one—limit:Number—would be the optional parameter that is used for specifying the number of items that are to be placed into the array.

Now, that you know what the syntax for the split() function is, try it and check the output for yourself. You can use this function when you want to parse out some data or want to remove or replace a string. Furthermore, you may want to check out the join() function as well if you seeking to write a piece of AS3 code for replacing a part of a long string.

Leave a Comment

If you would like to make a comment, please fill out the form below.


Name

Email

Website

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Comments

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word


Related Posts

9 Comments so far
  1. lol  April 21, 2008 10:36 am

    wtf?

  2. Tony Fendall  April 21, 2008 3:35 pm

    Isn’t this the same syntax as one would use when coding in java?

  3. Anonymous  April 22, 2008 4:39 am

    So you say you are a java developer? And what was so hard to figure out here starting from java’s String[] split(String regex,int limit) ?

  4. bebOp  October 16, 2008 7:02 pm

    He said he didn’t know about the Split() function.. pay attention before posting a comment…

    Thank you Jay, very clear and useful.

  5. Anonymous  February 24, 2009 12:00 pm

    I can see you are a java programmer, a example would be nice now and then… interesting how one can be so verbose about a split.

  6. Narnian  April 6, 2009 6:51 pm

    Thank you very much for pointing this out… found your page on the first hit in the search engine and you answered my question right on.

  7. Anonymous  June 1, 2009 10:36 am

    without example i find in adobe shit documentation

  8. anonymous  January 5, 2011 7:32 pm

    this is the worst fucking article i’ve ever read.

  9. eran  January 23, 2011 5:23 pm

    here is a sample :)

    var string:String=”one–two”;
    var array:Array=string.split(“–“);
    trace(array[1]);

    trace—-two

    Eran

<

Error. Page cannot be displayed. Please contact your service provider for more details. (6)


Direct TV Offers - usdirect has the best directtv deals