[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

How do I parse a string...

I have a variable that contains a "-" hyphen that separates two pieces of information.  How do I parse for it in Visual Basic:

Dim myFullVar as String
myFullVar = "Z23XYU53389-383838"
myVar1 =  'Your code will go here and return Z23XYU53389
myVar2 = 'Your code will go here and return 383838
0
frankmorrison
Asked:
frankmorrison
1 Solution
 
GrahamSkanCommented:
MyVar1 = Split(myFullVar, "-")(0)
MyVar2 = Split(myFullVar, "-")(1)
0
 
SethiCommented:
You can use Instr to find the position of the "-" in the string and then use the Mid function to extract the first and the last string. Or you can also use the Split function. I am displaying the Split function here.

Dim strSplit() as String
strSplit=Split("Z23XYU53389-383838","-")
myVar1 =strSplit(0)
myVar2 =strSplit(1)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now