Solved

string to array

Posted on 2014-01-22
6
285 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 51

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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

19 Experts available now in Live!

Get 1:1 Help Now