View Full Version : String using split()
Jerome
10-26-2002, 06:06 PM
Hi,
I set a cookie like:
NAME
VALUE1%A6VALUE2%A6VALUE3
~~local~~/C:\MYDOMAIN\
0
3488044672
29523393
2806071168
29523192
*
After I can read-out the VALUE, but this is the complete string!
I like to have the separate VALUEs 1 till 3 , like:
var var1=GetCookie('NAME');
if(var1!=null)
{
>>Here I like to have VALUE 1 till 3 with split('¦')
}
if(var1==null)
{
nothing
}
Thanks in advance,
Jerome
joh6nn
10-26-2002, 09:51 PM
i'm afraid i don't understand the problem.
Jerome
10-27-2002, 07:30 AM
Hi,
The Cookie I set looks like this:
NAME
VALUE1%A6VALUE2%A6VALUE3
~~local~~/C:\MYDOMAIN\
0
3488044672
29523393
2806071168
29523192
*
The VALUE from this cookie however, is built-up as a string, f.e.
VALUE1%A6VALUE2%A6VALUE3 = blue¦red¦green
After reading-out the string, I like to have a result like:
A=blue
B=red
C=green
For this I like to use the split() methode
Thanks in advance,
Jerome
joh6nn
10-27-2002, 08:10 AM
again, i don't understand the problem. you want to use the split() method. ok, great. so use it.
i'm afraid i simply don't see where you're having a problem.
Jerome
10-27-2002, 09:11 AM
Hi,
Sorry for making it so difficult, but it's more easy than You think!
I do not know how I can separate this string into 3 pieces!
How do I write a routine for this.
Jerome
whammy
10-27-2002, 09:44 AM
Well, if you can get the VALUE line, you're halfway there:
valuearray = VALUE.split("|");
alert(valuearray[0]);
alert(valuearray[1]);
alert(valuearray[2]);
However if you'd just looked up
javascript split() here (http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=javascript+split%28%29&btnG=Google+Search)
or
javascript split() join()
here (http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=javascript+split%28%29+join%28%29+&btnG=Google+Search) you probably would have figured it out already.
;)
Jerome
10-27-2002, 01:27 PM
Thanks!
whammy
10-29-2002, 12:08 AM
P.S. I'd probably use a different variable than VALUE though... it's just a bad habit (even though it's uppercase), since value is a reserved word in javascript (and a lot of other languages).
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.