Flasher Archive

[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]


Subject: Re: [flasher] String.split()
From: Helen Triolo
Date: Sun, 04 Feb 2001 14:29:37 -0000

Millie,

As far as I can see, you're right; the last sentence in the manual is
incorrect.

text="hello you";
letter=text.split("");
for (i=0;i<letter.length;i++) {
trace(" letter[" + i + "]: " + letter[i]);
}

returns --> letter[0]: hello you

(not letter[0]: h, letter[1]: e, etc)

and that sure looks like an empty string delimiter to me.

I'm sure you know this already, but you could get every letter into an
array element with this if you want:

nletter = new array();
for (i=0;i<text.length;i++) {
nletter[i] = text.substr(i,1);
trace(" nletter[" + i + "]: " + nletter[i]);
}

Regards,
Helen
-----------------------------------------------------
i-Technica � http://i-technica.com � 301.424.6037
developer resources: http://i-technica.com/whitestuff

Millie Maruani wrote:
>
> String.split
> Syntax
>
> myString.split(delimiter);
>
> Arguments delimiter The character used to delimit the string.
>
> Description Method; splits a String object by breaking the string wherever
> the specified delimiter argument occurs, and returns the substrings in an
> array. If no delimiter is specified, the returned array contains only one
> element-the string itself. If the delimiter is an empty string, each
> character in the String object becomes an element in the array.
>
> If the delimiter is an empty string, each character in the String object
> becomes an element in the array.
> this doesn't work!
> text="hello you";
> letter=new array();
> letter=text.split("");
> returns "hello you" exactly as letter=text.split();
>
> Am I mistaking?



[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]