?
Solved

Split a string into variables by (-)

Posted on 2003-11-21
8
Medium Priority
?
51,142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

719 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