Link to home
Start Free TrialLog in
Avatar of John Kincaid
John KincaidFlag for United States of America

asked on

How to parse space delimited string.

I need to capture all text to the right of the last space and everything (including spaces) to the left of the last space.  I have been all over the Mid, Right and Left functions. All messed up here!!!
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

The best solution is the Split Command
Dim AllText() as String
AllText = Split(YourText," ")
For i = Lbound(AllText) To UBound(AllText)
Debug.Print AllText(i)
Next

Open in new window

This will convert your text to an array splitted on each space
e.g.
YourText = "A Simple Test"
AllText(0) = "A"
AllText(1) = "Simple"
AllText(2) = "Test
ASKER CERTIFIED SOLUTION
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
EXPERT CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John Kincaid

ASKER

Anders

MyString = "Aaron Guzman"
 Mid(YourString, Len(YourString)) returned "n"
and
Left(YourString, InStrRev(YourString, "")) returned "Aaron Guzman"
In addition to Bill's correct solution, you can also use the Left() function:
Left([Text1],InStrRev([Text1]," ")-1) AS LeftPart

Open in new window

Anders, forgive me I am wrong, your code worked fine.
Bill, yours did as well.

Thanks to both of you!
Thanks again to everyone!
Avatar of Bill Prew
Bill Prew

Welcome.


»bp