Solved

Find first comma in VBScript..

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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