string to array

Hi there!

Suppose I have the following string:

stringExample =  CStr(Request.Form("certainfield"))

Just for the sake of the question, imagine  93, 94, 106, 114, 134 as the stringExample.

I would like to create an array (say arrayExample) such that:

arrayExample[0] = 93
arrayExample[1] = 94
arrayExample[4] = 134

Important: my string is made only of integers separated by commas, but the number of integers is not always the same.

Could you please show me how this could be done?

Who is Participating?
Big MontyConnect With a Mentor Senior Web Developer / CEO of Commented:
you could use either UBound (which'll get the top value for the array or you can use, what I prefer, a for each statement:

for each example in arrExample
   Response.Write example & "<br/>"

the example highlighted in bold can be whatever you like, think of it as a local variable exclusive to the for loop
Big MontySenior Web Developer / CEO of Commented:
simple, you want to use the Split() function:

stringExample =  CStr(Request.Form("certainfield"))
arrayExample = Split( stringExample, "," )        '-- use whatever your separator is for the second parameter
Bill PrewConnect With a Mentor Commented:
Keep in mind that the result of the split will be an array of strings.  You may need to use CInt() on the resulting elements if you want to use it in math or numerical work.

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

fskilnikAuthor Commented:
Thanks Big Monty... really simple!

Just one thing (that is part of my original question): what should I put in the place of ??? below...

dim arrayExample, stringExample

stringExample = "92, 23, 45"
arrayExample = Split(stringExample, "," )

for k = 0 to ???
Response.write arrayExample(k)
next k
fskilnikAuthor Commented:
Good point, bp ... I will need it as you said, by the way!  Thanks!
fskilnikAuthor Commented:
Uau... great!!

Thanks a lot, Big Monty (and bp).

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.