You don't need a loop for this:

 'Set replacement string
 R.ReplacementPattern = "" // Empty string

 ' Set Search Pattern.
 R.SearchPattern =  "("+Join(aCommonWords,"|")+")"
// will produce a searchpattern of
// (and|in|the|of|to|come)

Now the danger is that words containing the words you are looking for
will be truncated [ie band will become b, string will become strg,
etc). To avoid that, you need to specify that these are full words:

 ' Set Search Pattern.
 R.SearchPattern =  "(\W)("+Join(aCommonWords,"|")+")(\W)"
// search pattern is now (\W)(and|in|the|of|to|come)(\W)

 'Set replacement string
 R.ReplacementPattern = "\1\3"
// whatever was before and after the match

Now words like band string stone and the like, which contain and, to,
in etc, will not be truncated.

HTH

--
dda
libcurl4RB, [S]FTP transfers made easy
http://sungnyemun.org/?q=node/8

Code looks like:
 Dim aCommonWords() as String
 Dim theString as String
 Dim R as New RegEx

 aCommonWords=Array("and","in", "the", "of", "to", "come")
 theString = "here is a black and white cat with a red band and a
blue string on a stone operating a lathe"
 R.Options.Greedy = False
 R.Options.ReplaceAllMatches = True
 R.SearchPattern =  "(\W)("+Join(aCommonWords,"|")+")(\W)"
 R.ReplacementPattern = "\1\3"
 EditField1.Text = r.replace( theString )

On 6/9/06, Mark C <[EMAIL PROTECTED]> wrote:
Hi,

I've been trying to get a simple function to work, that passes in a string
and then loops through an array of words, if one of these words in in the string
it removes the word (replaces it with blank).

Thanks in advance

Mark
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to