Solved

Strings

Posted on 1998-12-12
5
144 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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…

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