Solved

How to parse a string with spaces inserted between letters

Posted on 2002-05-20
7
137 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month9 days, 21 hours left to enroll

623 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