Solved

Split a string into variables by (-)

Posted on 2003-11-21
8
51,140 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 350 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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/…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

622 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