Looping through a phrase to get "deliminated" words

  • Thread starter Thread starter DP
  • Start date Start date
D

DP

I'm wondering if someone could help me with a "string" expression question.

What I would like to do is simply enough described. With a phrase something
like this:

"First word - Second word - Third word - Fourth word - Fifth word" [the
phrases are sometimes shorter, sometimes longer]

I need code that will simply work its way through the phrase (or loop) and
successfully return the "contents" of the phrase, in this order:

First word
Second word
Third word
Fourth word,

Etc., stopping, of course, at whatever happens to be the last word.

Any help would be appreciated greatly.

David Pike
 
DP said:
I'm wondering if someone could help me with a "string" expression question.

What I would like to do is simply enough described. With a phrase something
like this:

"First word - Second word - Third word - Fourth word - Fifth word" [the
phrases are sometimes shorter, sometimes longer]

I need code that will simply work its way through the phrase (or loop) and
successfully return the "contents" of the phrase, in this order:

First word
Second word
Third word
Fourth word,

If the format of your "phrase" is consistent, then the Split function will
do exactly what you are asking.

strA = "First word - Second word - Third word - Fourth word - Fifth word"
varW = Split(strA, " - ")
For I = 0 To UBound(varW) - 1
Debug.Print varW(I)
Next I

First word
Second word
Third word
Fourth word

HTH,
Randy
 
It's just what I needed, thank you!

David Pike


Randy Harris said:
DP said:
I'm wondering if someone could help me with a "string" expression question.

What I would like to do is simply enough described. With a phrase something
like this:

"First word - Second word - Third word - Fourth word - Fifth word" [the
phrases are sometimes shorter, sometimes longer]

I need code that will simply work its way through the phrase (or loop) and
successfully return the "contents" of the phrase, in this order:

First word
Second word
Third word
Fourth word,

If the format of your "phrase" is consistent, then the Split function will
do exactly what you are asking.

strA = "First word - Second word - Third word - Fourth word - Fifth word"
varW = Split(strA, " - ")
For I = 0 To UBound(varW) - 1
Debug.Print varW(I)
Next I

First word
Second word
Third word
Fourth word

HTH,
Randy

Etc., stopping, of course, at whatever happens to be the last word.

Any help would be appreciated greatly.

David Pike
 
Back
Top