Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2014

    Smile Is there way in VBscript to extract the 1st, 2nd & 3rd words from a string?

    Hello everyone,

    I have a field named CityStateZip. It has a value like Milwaukee, WI 53203. I need to pull the first, second and third words separately using VBscript. Is there a way to do this if you don't always know the number of characters?

    Thank you in advance.

  2. #2
    Join Date
    Aug 2014
    You could use the Split() function. Like this:
    Dim ThreePart() as string
    Dim City, State, Zip as string
    ThreePart = Split(CityStateZip, " ")
    If UBound(ThreePart) >= 3 Then
    City = ThreePart(0)
    State = ThreePart(1)
    Zip = ThreePart(2)
    End If
    It should work for VBA. To use it in VBScript, remove the "As String" from the Dim statements. The syntax is a little different if you want to use it in TSQL.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.