Link to home
Start Free TrialLog in
Avatar of The-Jimmy
The-Jimmy

asked on

Split a string into variables by (-)

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
Avatar of kingsfan76
kingsfan76

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
ASKER CERTIFIED SOLUTION
Avatar of Dexstar
Dexstar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
one minor correction for the code above:

the line

theStr = "123456-1234-12

should be

theStr = "123456-1234-12"

forgot to close the quotes   :-)
@kingsfan76:

> use a split function to split them into array

Doh!  Hey Man, what's up?

Dex*
@Dex:

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

kingsfan
Avatar of The-Jimmy

ASKER

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
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
@kingsfan:

Nah, I was just quoting that because you posted my answer before I did... :)  Speaking of which, check this out:
     https://www.experts-exchange.com/questions/20805380/Points-for-KingsFan76-RE-Question-20805353.html

Dex*