Solved

Strings

Posted on 1998-12-12
5
146 Views
Last Modified: 2012-05-04
This should be a very easy one...  I feel stupid asking....  All I want to do is take a string and be able to extract each word from the string seperately.  In other words if I had a string that said "Jack and Jill went up the hill."  I would want to be able to take each of the words and look at them seperately and maybe do something to each one as I am going through (display them one at a time for instance..  or put them in another control)
0
Comment
Question by:fatalerror080298
[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
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
vikiing earned 50 total points
ID: 1449753
I%=0
Do
   I%=Instr(I%+1, Phrase$, " ")    'Look for a space
   If I%=0 then Exit Do            'If no more spaces, bye
   ThisWord$=Left$(Phrase$, I%-1)  'Pick up a word
   Phrase$=Mid$(Phrase$,I%+1)      'Remove word from phrase
   <do something with ThisWord$>
Loop                               'Keep on going

0
 
LVL 3

Expert Comment

by:vikiing
ID: 1449754
Ops !!!, I forgot to state:

I%=0 : Phrase$=Phrase$+" "   'Add a blank to not loose the last word
0
 

Author Comment

by:fatalerror080298
ID: 1449755
Not sure if this is what you mean in your comment but when I tried the code I noticed that each time I was picking up an extra word because the counter was not being re-initialized in the loop.  Anyway, after adding that it pretty much works.  I didn't really want to erase the originating text though.  But at least you pointed me in the correct direction.

I saw the functions StrSpan and StrBreak that seems like they would do what I want but I just need to figure out the correct usage for this situation.  I can't find any real good examples.

Thanks for your help!
0
 
LVL 3

Expert Comment

by:vikiing
ID: 1449756
Keep in mind that variable I% is NOT a counter, but a pointer indicator of where is the next space into the phrase. When no more spaces are found, I% returns (to) zero. Anyway, that's why just before DO loop I stated  I%=0

Thanks for the points !!
0
 

Author Comment

by:fatalerror080298
ID: 1449757
Found a better way to do it....  I believe this function (split) came around in VB 6...  Very nice...

    Dim i           As Integer
    Dim stringArray As Variant
       
    stringArray = Split(txtString, " ")
   
    For i = LBound(stringArray) To UBound(stringArray)
        msgReturn = MsgBox(stringArray(i), vbOKOnly, "Text Display")
    Next i
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month5 days, 6 hours left to enroll

636 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