Solved

Find first comma in VBScript..

Posted on 2009-07-14
3
470 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now