Click to See Complete Forum and Search --> : Cookies


fark
10-07-2003, 09:35 AM
I have this in my cookie
asdfsadf:sadfsadfasf:sdfasdfsadf:asdfsadf:asdfsadfasdf:test:test:test:test:test:test:::::
I read in my cookie with
Request.Cookies (Item)
I need to split that text string into the seperate parts and put it into variables. How do I split Item up between the colons so I can use the values???

learninghtml
10-17-2003, 01:46 AM
Hi,
This is not a job for HTML. It can be done in javascript...

Basically load the entire string into a variable...

Then loop character by character to the end of the string. In each loop check if the character is a ':'.

If the values between the colons are sequentially...
I.E. The values are in a specific order.

Use another variables to hold the index of the colon. Then write character by character what ever follows the colon until you come to the next colon.

When you reach the next colon, move to your next variable in the sequence and transfer the following characters to it and so on to the end of the string.

It's fiddly but not impossible.

But, I'm sure that someone out there will know an easier way of doing it or will have some code to do it already written.

Hope that helps....

Khalid Ali
10-17-2003, 09:24 AM
a faster and easier way will be to get the cookie

dataArray = cookieStr.split(":")

the above will create an array of values separated bycolons in the string.A thing to remember is that the first array aindex will have evrything beofre the first split and last will have the rest of the string.

learninghtml
10-17-2003, 09:41 AM
Hi Khalid,
I thought they maybe a (is it a function or a method?) but couldn't be sure.

Would you mind if I copy and paste that code to a text file for future reference?

Regards