Consulting

Results 1 to 2 of 2

Thread: Extracting strings from a string

  1. #1

    Extracting strings from a string

    Hello,

    I need a macro that will separate an inputted string into multiple strings.

    Example 1
    The string "text1,text2,text3" was inputted. The result should be:

    ResultsArr(1) = "text1"
    ResultsArr(2) = "text2"
    ResultsArr(3) = "text3"

    Example 2
    The string "hello1,hello2,hello3,...,helloN" was inputted. The results should be:

    ResultsArr(1) = "text1"
    ResultsArr(2) = "text2"
    ResultsArr(3) = "text3"
    ...
    ResultsArr(N) = "textN"


    Please note:
    1. The text in the string is unknown. The only known fact is that the string contains commas. The characters between each comma should be extracted into separate strings.
    2. The size of the array can be determined by: (# of commas in the string) + 1
    3. We can assume that the size of the array will not exceed 20.
    Do you know what is the most efficient way to implement this?

    Any help will be very appreciated.

    Thank you!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Take a look at Split in VBA Help, it does it all.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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