Skip to main content
March 19, 2008
Answered

toString then split() don't work!

  • March 19, 2008
  • 6 replies
  • 974 views
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
This topic has been closed for replies.
Correct answer
Aha. Me thinks we're getting somewhere now. Something like this perhaps?
And of course, this would be more efficient

6 replies

March 19, 2008
lol. Sorry-- though I was in the AS3 forum. But the same applies to AS2 classes.
March 19, 2008
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.

March 19, 2008
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
Inspiring
March 19, 2008
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";
}

Does that help?


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


March 19, 2008
It certainly works here.
March 19, 2008
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
March 19, 2008
Aha. Me thinks we're getting somewhere now. Something like this perhaps?
Inspiring
March 19, 2008
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? ....
March 19, 2008
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



Inspiring
March 19, 2008
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."


March 19, 2008
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???"