Link to home
Start Free TrialLog in
Avatar of smkkaleem
smkkaleem

asked on

How to parse a string with spaces inserted between letters

I want to parse strings with spaces inserted between the three character long letters and add them into an array. What will be the most efficient method. Following is the example of the types of strings I want to parse:

"ESM  ESX  E8C            "

Any quick code will be appreciated.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland 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
This only works in VB6 though so if you have an older version it will not. I can give you a function that works in vb5 if you want.
Avatar of smkkaleem
smkkaleem

ASKER

what about VB.NET? Does the split function work in VB.NET?
The split function works exactly the same in VB.NET
If the codes contain multiple spaces between them, you may need to filter them out first with something like this:

strCodeList = "ESM  ESX  E8C            "

' get rid of leading and trailing spaces
strCodeList = Trim$(strCodeList)

' Replace all double-spaces with single spaces
while instr(strCodeList, "  ") > 0
  strCodeList = Replace(strCodeList, "  ", " ")
wend

' Now put into an array
dim strCodeArray() as string
strCodeArray = split(strCodeList, " ")
Avatar of DanRollins
Hi smkkaleem,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept TimCottee's comment(s) as an answer.

smkkaleem, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange