PDA

View Full Version : Extracting strings from a string



Ben.N
08-01-2011, 09:18 AM
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:
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.
The size of the array can be determined by: (# of commas in the string) + 1
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!

Bob Phillips
08-01-2011, 09:55 AM
Take a look at Split in VBA Help, it does it all.