A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Split string into an array

  1. #1
    Member
    Join Date
    Nov 2003
    Posts
    49

    Split string into an array

    I want to split a string into an array, for example :

    aString="a b c d";

    The result should be an array :

    a[1] = "a"
    a[2] = "b"
    a[3] = "c"
    a[4] = "d"

    Anyone know how to do this using actionscript ?

  2. #2
    Senior Member charlie_says's Avatar
    Join Date
    Feb 2003
    Location
    UK
    Posts
    508
    ok
    Code:
    a = aString.split(" ")
    will work for you.

    BUT

    arrays start at 0, not 1
    so you will in fact get:
    a[0] = "a"
    a[1] = "b"
    a[2] = "c"
    a[3] = "d"

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    1
    Hello,

    Would you know how to split this kind of array?

    var xmlTournamentStartDate:Array = "2013-06-10 15:20:01";
    tmp = xmlTournamentStartDate.split("-");
    tmp2 = xmlTournamentStartDate.split(":");

    I need to split all the numbers to be able to use them around as i need, the final format of this would be :

    10 JUNE * 15h20 (french format)

    I know how to make a function that replaces number by a month but i'm a bit stuck on the split function... maybe we can't split this kind of format?

    Thanks!

  4. #4
    Registered User
    Join Date
    Sep 2013
    Posts
    1
    Quote Originally Posted by rolandla View Post
    Hello,

    Would you know how to split this kind of array?

    var xmlTournamentStartDate:Array = "2013-06-10 15:20:01";
    tmp = xmlTournamentStartDate.split("-");
    tmp2 = xmlTournamentStartDate.split(":");

    I need to split all the numbers to be able to use them around as i need, the final format of this would be :

    10 JUNE * 15h20 (french format)

    Thanks!
    This is probably a little late, but as I was passing:

    var str:String="2013-06-10 15:20:01"
    var tempArr:Array=str.split("-")
    var tempArr2:Array=tempArr[2].split(":")
    var newStr:String=tempArr[0]+" JUNE * "+tempArr2[0]+"h"+tempArr2[1];
    trace(newStr)//2013 JUNE * 10 15h20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center