Solved

I need help parsing a string in VB6

Posted on 2013-11-15
5
313 Views
Last Modified: 2013-12-04
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
0
Comment
Question by:mainrotor
[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
  • 3
  • 2
5 Comments
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39651637
strVar2 = Split(strVar1,",";")(0)
strVar3 = Split(strVar1,",";")(1)
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39651642
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
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39651646
My code was wrong it should be
strVar2 = Split(strVar1,";")(0)
strVar3 = Split(strVar1,";")(1)
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39651648
But if you have a limited number of elements it's not easier than Martin's recommendation
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39670784
Did any of the above help you?
0

Featured Post

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!

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

726 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