Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Find first comma in VBScript..

Posted on 2009-07-14
3
Medium Priority
?
501 Views
Last Modified: 2012-05-07
Hello All-

I need to use VBScript to parse out a string into a smaller string.  For instance, I might have a string value of "511 Fairdale, Cypress, Texas 77666".  I need to use VbScript to populate another string with all characters up to the first comma like "511 Fairdale".  Does someone have the code to do this?

Many thanks,
0
Comment
Question by:JoshinHtown
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24854456
simple:
string2 = left(string1 & "," , instr(1, string1 & "," , ",")-1)

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24854474
what about (you posted also in .NET, is it VBScript you need or VB.NET?):

Dim somestring As String = "511 Fairdale, Cypress, Texas 77666"
Dim newstring As String = Left(somestring, Instr(1, somestring, ",") - 1)
 
' newstring now contains "511 Fairdale"

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24854487
Ah, I see that AngelIII already gave you code, with an added comma to prevent your code to err on that line, i.e., when there would be no comma to begin with, in which case his code will return the full string.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Loops Section Overview

927 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