[thelist] ASP: First 100 words in a record

Michael Mell mike at nthwave.net
Wed Jun 19 15:37:01 CDT 2002


I looked for a regular expression solution without success.
But I was a slacker, so I tried again:
This will pull the first 100 "words"
++++++++++++++++++++++++++
import re
sourceString = 'asdf qwer, qert tiu s aegf. asdf qwer qert tiu s aegf
asdf qwer qert tiu s ae '
compiledRE = re.compile('(.+?\s){0,100}')
result = compiledRE.match(sourceString)
print result.group(0)
++++++++++++++++++
It's written in Python. I know you're on ASP, and I don't know if ASP
does RegEx, but this would be an approach.


Robert Goodyear wrote:

> What about somthing like this? CAVEAT: just rambling
> at the keyboard here, so this code is not valid, nor
> do I know if you can nest and exit loops like this.not sure about
> efficiency, but if you're going this route, you might as well check
> each character from the beginning, counting the word boundary
> characters as you go. When you hit 100 word boundary characters,
> you've got your first 100 words.

not sure about efficiency, but if you're going the loop route, you might
as well check each character from the beginning, counting the word
boundary characters as you go. When you hit 100 word boundary
characters, you've got your first 100 words.


--
mike[at]nthwave.net
llemekim         YahooIM
415.455.8812     voice
419.735.1167     fax





More information about the thelist mailing list