From: yukabuk on
> No. When I print varValue I get "A";"B";...."N"

No you don't... ;-)
You get 'A'
From: yukabuk on
> No. When I print varValue I get "A";"B";...."N"

No you don't... ;-)
You get 'A'

From: Lasse Reichstein Nielsen on
HerbF(a)earthlink.net writes:

> I have a variable constructed as:
>
> varValue = "A";"B";..."N"

From your other messages, I assume it's something like
varValue = '"A";"B";...;"N"'

> How do I count how many elements, A, B,...n?
>
> Currently, I'm doing:
>
> varArray = varValue.split(";");
> varEls = varArray.length;
>
> Is this reliable, or is there a better way?

If there are no other semicolons than the ones separating your
elements, it should split the string into those elements.

It's a waste of time and space to make all those small strings
if you don't need them.
You could also do something like this:

var count = 0;
for (var i = varArray.indexOf(";");
i >= 0;
i = varArray.indexOf(";", i + 1)){
count++;
}

Good luck.
/L
--
Lasse Reichstein Holst Nielsen
'Javascript frameworks is a disruptive technology'

From: HerbF on
Lasse Reichstein Nielsen wrote:

>HerbF(a)earthlink.net writes:
>
>> I have a variable constructed as:
>>
>> varValue = "A";"B";..."N"
>
>From your other messages, I assume it's something like
> varValue = '"A";"B";...;"N"'

No double quotes around the package. "A";"B"....
>
>> How do I count how many elements, A, B,...n?
>>
>> Currently, I'm doing:
>>
>> varArray = varValue.split(";");
>> varEls = varArray.length;
>>
>> Is this reliable, or is there a better way?
>
>If there are no other semicolons than the ones separating your
>elements, it should split the string into those elements.
>
>It's a waste of time and space to make all those small strings
>if you don't need them.

They're not strings, and I do need them.

>You could also do something like this:
>
> var count = 0;
> for (var i = varArray.indexOf(";");
> i >= 0;
> i = varArray.indexOf(";", i + 1)){
> count++;
> }

This is identical to what I started with. (There are one less semicolon
than there are elements, so it's necessary to add 1 to the total.)
>
>Good luck.
>
Thanks, and thanks for your input.
H-
From: Hamish Campbell on
On Jun 26, 11:10 am, He...(a)earthlink.net wrote:
> Lasse Reichstein Nielsen wrote:
> >He...(a)earthlink.net writes:
>
> >> I have a variable constructed as:
>
> >> varValue = "A";"B";..."N"
>
> >From your other messages, I assume it's something like
> > varValue = '"A";"B";...;"N"'
>
> No double quotes around the package. "A";"B"....
>
>
>
> >> How do I count how many elements, A, B,...n?
>
> >> Currently, I'm doing:
>
> >> varArray = varValue.split(";");
> >> varEls = varArray.length;
>
> >> Is this reliable, or is there a better way?
>
> >If there are no other semicolons than the ones separating your
> >elements, it should split the string into those elements.
>
> >It's a waste of time and space to make all those small strings
> >if you don't need them.
>
> They're not strings, and I do need them.
>
> >You could also do something like this:
>
> > var count = 0;
> > for (var i = varArray.indexOf(";");
> >      i >= 0;
> >      i = varArray.indexOf(";", i + 1)){
> >   count++;
> > }
>
> This is identical to what I started with. (There are one less semicolon
> than there are elements, so it's necessary to add 1 to the total.)
>
> >Good luck.
>
> Thanks, and thanks for your input.
> H-

*headdesk*