Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

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?

Thanks,
fskilnik.
0
fskilnik
Asked:
fskilnik
  • 3
  • 2
2 Solutions
 
Big MontySenior Web Developer / CEO of ExchangeTree.org 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
0
 
Bill PrewCommented:
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.

~bp
0
 
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
fskilnikAuthor Commented:
Good point, bp ... I will need it as you said, by the way!  Thanks!
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org 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/>"
next

the example highlighted in bold can be whatever you like, think of it as a local variable exclusive to the for loop
0
 
fskilnikAuthor Commented:
Uau... great!!

Thanks a lot, Big Monty (and bp).

Regards,
fskilnik.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now