PDA

View Full Version : break variable to smaller ones


medmuseum
05-31-2003, 10:12 AM
I'd like to ask how I can break the value of a variable to other variables every certain character ( "+" or "," or any other character)...

e.g.

variable = "blue,apple,square,345"


I want to use this to give the following variables these values:

color = "blue"
fruit = "apple"
shape = "square"
number = "345"


I hope I could explain what I mean

thanx

Frank
05-31-2003, 02:05 PM
Originally posted by medmuseum
I'd like to ask how I can break the value of a variable to other variables every certain character ( "+" or "," or any other character)...

e.g.

variable = "blue,apple,square,345"


I want to use this to give the following variables these values:

color = "blue"
fruit = "apple"
shape = "square"
number = "345"


I hope I could explain what I mean

thanx

You could use the Split() function.

arrAttributes = Split(variable, ",")

This would break up the string, using the comma as the delimeter, and put the values into an array named arrAttributes. You could replace the comma between the quote marks with the plus symbol, or even a space.

Your array would look like this:

arrAttributes(0) = "blue"
arrAttributes(1) = "apple"
arrAttributes(2) = "square"
arrAttributes(3) = "345"

From here you can use the array as is, or you can assign the values to the other variables you mentioned above.

color = arrAttributes(0)
fruit = arrAttributes(1)
shape = arrAttributes(2)
number = arrAttributes(4)

This may not be the most efficient way if your ASP applicaton is huge, but if it's a small app this could probably be useful.

HTH!
Frank

medmuseum
05-31-2003, 10:22 PM
thanx a lot , that was very helpful