Solved

string to array

Posted on 2014-01-22
6
287 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 33

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 53

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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 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