Results 1 to 3 of 3

Thread: How to manipulate this string

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    9

    How to manipulate this string

    Hi all,

    I need to be able to take substrings of the below string that is entered into a textbox in VB6. The string is an address and I need to take a substring of the City, State, Street, Zip Code, and Country


    400 Main Street
    East Manchester, TX 12345


    So I basically need the substrings like this:
    Street= 400 Main Street
    City = East Manchester
    State = TX
    Zip = 12345


    Your help is greatly appreciated...
    Last edited by Mr_Bateman; Jul 5th, 2012 at 08:29 AM. Reason: Forgot a detail

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: How to manipulate this string

    There is no good way to do this. But if you are sure that the data will always be in this format, then here is the basic algorithm to follow.

    1. Replace CRLF with comma.
    2. Split on comma.
    3. First part of the splitted string is Street, second is City.
    4. Split the third part on space.
    5. The first part of this splitted string is your State and second part is the Zip.

    You can use the Split function and Replace function to do this job.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: How to manipulate this string

    If this is really VB6, then it is in the wrong forum, though what Pradeep suggested holds true for any language.
    My usual boring signature: Nothing

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width