Solved

Split a string into variables by (-)

Posted on 2003-11-21
8
51,135 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 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
Independent Software Vendors: 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!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

713 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