Solved

Find first comma in VBScript..

Posted on 2009-07-14
3
488 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
[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
  • 2
3 Comments
 
LVL 143

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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

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…
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 …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

631 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