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

x
?
Solved

Split a string into variables by (-)

Posted on 2003-11-21
8
Medium Priority
?
51,146 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
ID: 9799090
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 1400 total points
ID: 9799093
@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
ID: 9799100
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
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.

 
LVL 19

Expert Comment

by:Dexstar
ID: 9799101
@kingsfan76:

> use a split function to split them into array

Doh!  Hey Man, what's up?

Dex*
0
 
LVL 12

Expert Comment

by:kingsfan76
ID: 9799201
@Dex:

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

kingsfan
0
 
LVL 2

Author Comment

by:The-Jimmy
ID: 9799222
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
ID: 9799261
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
ID: 9799271
@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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month6 days, 5 hours left to enroll

773 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