Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Wiki Markup
{description}
{excerpt}Searches for a specified string and returns a collection of type [SearchMatch\[\]|SearchMatch].{excerpt}
{signature:C#}
 public virtual SearchMatch[] Search(System.String toMatch)
{signature}{signature:vb.net}
Public Overridable Function Search(ByVal toMatch As String) As SearchMatch()
{signature}
{parameters}
{param:toMatch}The string to find.{param}
{returns}A collection of [SearchMatch] objects.{returns}
{remarks}
 The search string can be a literal, a regular expression, or a combination of both. Since the string can contain regular expressions, use a  backslash to escape special characters. Special characters are {{[\^$.|?*+(){\}}}. The collection this method returns implements the .NET IEnumerable interface that can be used to iterate over the search results.
{remarks}
{example}{code:csharp|title=C#}

          //--- Required for IEnumerator
          using System.Collections;

          WordApplication app = new WordAppliation();
          Document doc = app.Open(@"c:\myDoc.doc");

          //--- Search a document for social security numbers, or any series of
          //--- nine digits, and remove them. The question mark after each dash
          //--- makes the presence of the dash optional.
          IEnumerator searcherator = (doc.Search(@"\d\d\d-?\d\d-?\d\d\d\d")).GetEnumerator();
          while (searcherator.MoveNext())
          {
               SearchMatch match = (SearchMatch)searcherator.Current;
               match.Element.DeleteElement();
          }
        {code}
{code:vb.net|title=vb.net}

          '--- Required for IEnumerator
          Imports System.Collections

          Dim app As New WordAppliation()
          Dim doc As Document = app.Open("c:\myDoc.doc")

          '--- Search a document for social security numbers, or any series of
          '--- nine digits, and remove them. The question mark after each dash
          '--- makes the presence of the dash optional.
          Dim searcherator As IEnumerator = (doc.Search("\d\d\d-?\d\d-?\d\d\d\d")).GetEnumerator()
          While searcherator.MoveNext()
               Dim match As SearchMatch = searcherator.Current
               match.Element.DeleteElement()
          End While
        {code}

{example}