Solved

I need help parsing a string in VB6

Posted on 2013-11-15
5
318 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

724 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