Solved

Split a string into variables by (-)

Posted on 2003-11-21
8
51,129 Views
Last Modified: 2007-12-19
Hey Guys,

I have these strings that come like this: 123456-1234-12

I need to set variables for each for of the sections seperated by the (-).
I believe this can be done with Mid and Instr, but I not sure about the syntax.

Thanks for the help,

- The Jimmy
0
Comment
Question by:The-Jimmy
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:kingsfan76
Comment Utility
use a split function to split them into array

dim arrStr
dim theStr

theStr = "123456-1234-12

arrStr = Split(theStr,"-")

for i=0 to Ubound(arrStr)
     response.write(arrStr(i))
next
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 350 total points
Comment Utility
@The-Jimmy:

> I have these strings that come like this: 123456-1234-12

Do this:

     Dim arr
     arr = Split( "123456-1234-12", "-" )

Then you can reference each section like this:
     arr(0) ' Would be 123456
     arr(1) ' Would be 1234

Follow?  Let me know what parts you aren't clear on.

Hope That Helps,
Dex*
0
 
LVL 12

Expert Comment

by:kingsfan76
Comment Utility
one minor correction for the code above:

the line

theStr = "123456-1234-12

should be

theStr = "123456-1234-12"

forgot to close the quotes   :-)
0
 
LVL 19

Expert Comment

by:Dexstar
Comment Utility
@kingsfan76:

> use a split function to split them into array

Doh!  Hey Man, what's up?

Dex*
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 12

Expert Comment

by:kingsfan76
Comment Utility
@Dex:

huh?  split the string into array variable...  something wrong with my wording?... hmm...

kingsfan
0
 
LVL 2

Author Comment

by:The-Jimmy
Comment Utility
Thanks Guys,

I liked the Dex approch .. real nice!
I'm woking on an intranet at the moment I could certainly use some help. Especially with JavaScript, validations and stuff. Its kinda urgent really ... if you want to make some bucks lemme know, my msn is jeryenergy@hotmail.com
0
 
LVL 12

Expert Comment

by:kingsfan76
Comment Utility
it's cool.  we have the identical solution, but I guess Dex is more explainatory (hmm is there a word "explainatory"...)
anyway, it's a good idea to use UBound() and a for loop to avoid having the "array out of bound" error
0
 
LVL 19

Expert Comment

by:Dexstar
Comment Utility
@kingsfan:

Nah, I was just quoting that because you posted my answer before I did... :)  Speaking of which, check this out:
     http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20805380.html

Dex*
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

6 Experts available now in Live!

Get 1:1 Help Now