Solved

How to parse a string with spaces inserted between letters

Posted on 2002-05-20
7
132 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:smkkaleem
7 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
ID: 7021640
Use split:

Dim aryBits() As String
Dim MyString As String
MyString = "ESM ESX E8C"
aryBits = Split(MyString," ")
Msgbox aryBits(0) & vblf & aryBits(1) & vblf & aryBits(2)


0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7021643
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.
0
 
LVL 2

Author Comment

by:smkkaleem
ID: 7021657
what about VB.NET? Does the split function work in VB.NET?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 7

Expert Comment

by:Joe_Griffith
ID: 7021675
The split function works exactly the same in VB.NET
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7022025
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, " ")
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7818282
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
0
 

Expert Comment

by:SpideyMod
ID: 7909750
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question