Hi Mark,

use ElfData! MSR especially.

dim msr as new msr

msr.Add "and", nil
msr.Add "in", nil
msr.Add "the", nil
msr.Add "of", nil
msr.Add "to", nil
// etc etc etc

theString = msr.ReplaceAll(theString)

All done!!

one thing though, the above example is bad code, because we are creating a new msr object everytime we do the replacement. It's better to create an msr and cache it for next time, like this:


dim module_msr_common as msr
function RemoveCommonWords() as MSR
  if module_msr_common = nil then
    module_msr_common = new msr
    module_msr_common.add "and", nil
    /// etc etc
  end if
  return module_msr_common
end function

This way, you make it all nice and fast :)

Even better is to remove the hard coding of the calls to .add, and just split some fields by a seperator and add the fields.



From: "Mark C" <[EMAIL PROTECTED]>
Date: Fri, 9 Jun 2006 12:49:47 +0100

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).

But for the life of me I cannot get this to work correctly, the code
needs more work to effectively remove the correct word match, but once
I can get the basics to work I can carry on with the rest

i.e:

<code>
  Dim aCommonWords() as String
  Dim theString as String

  Dim theString = "here is a black and white cat"

  // Common words to remove.
  aCommonWords=Array("and","in", "the", "of", "to", "come")

  // Stores the DocumentField text in the following string
  Dim R as RegEx

  'Initialize new regex object
  R = New RegEx

  'Set our regex options
  R.Options.Greedy = False
  R.Options.ReplaceAllMatches = True

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

  For i as Integer=0 to UBound( aCommonWords )

    ' Set Serach Pattern.
    R.SearchPattern =  aCommonWords(i)

    ' check for a match
if R.Search( theString ) <> Nil then theString = r.replace ( theString )

  Next

</code>

Thanks in advance

--
http://elfdata.com/plugin/



_______________________________________________
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