Thanks,
Jeff
The "Split" function is exactly what you need.
--
Helge Wunderlich
(Please remove the spam trap if you wish to send email)
Yup, it was. Why can't I ever seem to find these when I need them...?
:)
Thanks,
Jeff
Had you crossposted only one copy question to both NGs at the same time (instead of multiposting separate copies to each) you would have seen Steve's answer here as well...
--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--
I'm curious why RegExp is a better solution than Split. I don't doubt
you, I have yet to use RegExp for anything.
>Had you crossposted only one copy question to both NGs at the same time (instead of multiposting separate copies to each) you would have seen Steve's answer here as well...
Yeah, yeah. :)
I posted here, then found the other group later. :(
Thanks,
Jeff
Because it handles arbitrary, uneven spacing of words as well as understanding punctuation...
text = "This, is a sentence..."
has only 4 "words".
Using split(text," ") will give more that 4 "words", many that are empty (null strings) and 2 with punctuation tacked on the end as part of the word.
Try this with Steve's RegExp solution and you get only 4 non-empty words with punctuation ignored.
As long as you're singing my praises, and in light of the OP's innocence of
RegExps, I suppose I should provide a more complete solution. This pattern
will count contractions and hyphenated words as one word:
Sentence = "'This sentence isn't contraction-free,' she said."
With New RegExp
.Pattern = "\b[\w'\-]+\b"
.Global = True
Set Words = .Execute(Sentence)
End With
For Each Word In Words
WScript.Echo Word
Next 'Word
--
When one has too great a dread of what is impending, one feels some relief
when the trouble has come. -Joseph Joubert
=-=-=
Steve
-=-=-
This also solves another issue with Split I've run into, where I don't
know the length of the sentence but need the fifth word and the eighth
word if it exists. Here I just parse each word, if it's what I want I
assign it to a variable, if not, move on.
Thanks again, this is a better lesson than any book. :)
Jeff