Solved

Find first comma in VBScript..

Posted on 2009-07-14
3
465 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
Comment Utility
simple:
string2 = left(string1 & "," , instr(1, string1 & "," , ",")-1)

Open in new window

0
 
LVL 39

Expert Comment

by:abel
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

13 Experts available now in Live!

Get 1:1 Help Now