Solved

string to array

Posted on 2014-01-22
6
286 Views
Last Modified: 2014-01-22
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
Comment
Question by:fskilnik
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 39801184
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
 
LVL 52

Assisted Solution

by:Bill Prew
Bill Prew earned 20 total points
ID: 39801204
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
 

Author Comment

by:fskilnik
ID: 39801228
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:fskilnik
ID: 39801241
Good point, bp ... I will need it as you said, by the way!  Thanks!
0
 
LVL 32

Accepted Solution

by:
Big Monty earned 480 total points
ID: 39801244
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
 

Author Comment

by:fskilnik
ID: 39801259
Uau... great!!

Thanks a lot, Big Monty (and bp).

Regards,
fskilnik.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now