I need help parsing a string in VB6

Hi Experts,
I have a string in my VB6 application, which holds two values separated by a semi-colon.  I want to parse the string and put the values into separate strings.  How can I do that?


Example of what I want to accomplish

Dim strVar1 as string
Dim strVar2 as string
Dim strVar3 as string

strVar1 = "THIS;ROCKS"


I want to parse strVar1 and put each of the values separated by the semi-colon into the other two string variables:
strVar2 = "THIS"
strVar3 = "ROCKS"


Thanks in advance,
mrotor
mainrotorAsked:
Who is Participating?
 
Martin LissOlder than dirtCommented:
strVar2 = Split(strVar1,",";")(0)
strVar3 = Split(strVar1,",";")(1)
0
 
GrahamSkanRetiredCommented:
It would be easier to use an array and the Split function:
Dim strVars() as string
strVars = Split("THIS;ROCKS", ";")

Open in new window

0
 
Martin LissOlder than dirtCommented:
My code was wrong it should be
strVar2 = Split(strVar1,";")(0)
strVar3 = Split(strVar1,";")(1)
0
 
GrahamSkanRetiredCommented:
But if you have a limited number of elements it's not easier than Martin's recommendation
0
 
Martin LissOlder than dirtCommented:
Did any of the above help you?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.