Solved

Strings

Posted on 1998-12-12
5
141 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
Comment Utility
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
Comment Utility
Ops !!!, I forgot to state:

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

Author Comment

by:fatalerror080298
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no 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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now