13 Replies Latest reply on Mar 19, 2008 10:56 AM by Raymond Basque

    toString then split() don't work!

    GerryIsHere Level 1
      Hi there!

      I applied to an Array the toString method and the split method to the obtained result.
      This doesn't work.
      What is the best process to use?
      I want to obtain the split result as html formatted strings which I can display in an html enabled Text Field.

      I thank you in advance for any help!

      Best regards,
      Gerry
        • 1. Re: toString then split() don't work!
          Level 7
          Gerry,

          > I applied to an Array the toString method and the split method
          > to the obtained result.
          > This doesn't work.

          It might, actually. ;) Depends on exactly what you're after. Can you
          show the code you've used so far?

          > I want to obtain the split result as html formatted strings which
          > I can display in an html enabled Text Field.

          Let's see your code so far, including a brief examle of your current
          array contents, and also a brief example of the ultimate formatting in which
          you'd like the text to appear.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: toString then split() don't work!
            Rothrock Level 5
            It would be best if you showed us the code you are using. I'm trying to figure out what kind of stuff you have in your array. How you split it? What exactly isn't working? ....
            • 3. Re: toString then split() don't work!
              GerryIsHere Level 1
              Thanks Rothrock for responding!

              I give you below the code I use.
              I declared comboSelectedLabels as a new Array for the purpose of testing.
              In real world, it is an existing and working Array.
              The trace() statements return undefined...

              Best,
              Gerry



              • 4. toString then split() don't work!
                GerryIsHere Level 1
                Hi David!

                Here is the array (traced and copied from the output window):
                comboSelectedLabels = Cinéma et musicalité* (v.3 n˚1),Dispositif(s) du cinéma (des premiers temps)* (v.14 n˚1),La théorie du cinéma... enfin en crise** (v.17 n˚2-3),Écrit / écran* (v.4 n˚1)

                I want to get the following which will display in a selectable dymamic text field:
                Cinéma et musicalité* (v.3 n˚1)
                Dispositif(s) du cinéma (des premiers temps)* (v.14 n˚1)
                La théorie du cinéma... enfin en crise** (v.17 n˚2-3)
                Écrit / écran* (v.4 n˚1)

                Seems simple, hey?

                Best,
                Gerry

                PS: You can also watch "Data Grid in a List Component???"
                • 5. Re: toString then split() don't work!
                  Raymond Basque Level 4
                  It certainly works here.
                  • 6. Re: toString then split() don't work!
                    Level 7
                    Gerry,

                    > "Raymond Basque" <webforumsuser@macromedia.com> wrote
                    > in message news:frre65$o1m$1@forums.macromedia.com...
                    > It certainly works here.

                    Agreed. In principle, you're taking an array, converting it to a
                    string, then converting that comma-delimited string back into an array.
                    It's an effort in tautology ... unless I misunderstand what you're after,
                    you're ending up with the same thing you started with.

                    In your sample code from an earlier post in this thread, you ended up
                    naming a variable "myNewString," but you set it to an array.

                    var comboSelectedLabels:Array = new Array("a", "b", "c");
                    var myString:String = comboSelectedLabels.toString();
                    trace(myString);
                    var myNewString:Array = myString.split(",");
                    trace(myNewString);

                    In this revision, I've tried to clarify that. The String.split() method
                    returns an array (see the String.split() entry in the AS2 Language
                    Reference), so you wouldn't easily be able to populate a text field with the
                    content of myNewString.

                    If you want to display your list in a text field, you can step through
                    the original array's elements and use a for() loop. I'm not sure if this is
                    what you're after, but for what it's worth ...

                    var comboSelectedLabels:Array = new Array("a", "b", "c");

                    for (var n:Number = 0; n < comboSelectedLabels.length; n++) {
                    myTextField.text += comboSelectedLabels[n] + "\n";
                    }

                    Does that help?


                    David Stiller
                    Co-author, Foundation Flash CS3 for Designers
                    http://tinyurl.com/2k29mj
                    "Luck is the residue of good design."


                    • 7. Re: toString then split() don't work!
                      GerryIsHere Level 1
                      Hi Raymond!

                      Thanks for your reply.

                      Yes it works.
                      But not for split()...
                      I still have the whole text without any break in place of commas after each title.

                      How can I achieve this?

                      Best,

                      Gerry


                      PS: In real world, I don't have any double quotes in my Array
                      • 8. Re: toString then split() don't work!
                        Raymond Basque Level 4
                        Aha. Me thinks we're getting somewhere now. Something like this perhaps?
                        • 9. Re: toString then split() don't work!
                          Raymond Basque Level 4
                          And of course, this would be more efficient
                          • 10. Re: toString then split() don't work!
                            GerryIsHere Level 1
                            quote:

                            Originally posted by: Raymond Basque
                            And of course, this would be more efficient


                            CONGRATULATIONS, Raymond, you got it.
                            myNewString displays perfectly in an html enabled text field: each title is on its own line!

                            You really are a guru... :-)
                            I thank you for this very efficient help.

                            Sorry, David, ones can't always win! Ah ah ah !!!
                            But I thank you too, of course. You point something so interesting as if I was watching a dog running after its tail... That's me!!!

                            Best,
                            Gerry

                            PS: With such a name, Raymond, are you French? I am.





                            • 11. Re: toString then split() don't work!
                              Raymond Basque Level 4
                              LOL. You're welcome GerryIsHere.
                              I would hesitate to use that "guru" word. There are plenty of folks frequenting these forums who could have pointed you in the right direction - David Stiller among them.
                              I would recommend you take a little time to look at some of the core AS3 classes. A little understanding of the Array and String classes can save you a lot of wasted time.

                              • 12. Re: toString then split() don't work!
                                GerryIsHere Level 1
                                You certainly are right.
                                Maybe "guru" is a little exagerated...

                                I don't have AS3. I stick to AS2 because the few things I saw about AS3 didn't please me.
                                I think it is as complicated as the is not NaN logic... ha ha ha.
                                :-)

                                Gerry
                                • 13. Re: toString then split() don't work!
                                  Raymond Basque Level 4
                                  lol. Sorry-- though I was in the AS3 forum. But the same applies to AS2 classes.