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
Description

Excerpt

Searches for a string specified by the search parameter, and replaces it with the string specified by the replaceWith parameter. 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 [^$.|?*+().

Signature
C#
C#
 public virtual int SearchAndReplace(System.String search, System.String replaceWith)
Signature
vb.net
vb.net
Public Overridable Function SearchAndReplace(ByVal search As String, ByVal replaceWith As String) As Integer
Parameters
Param
search
search

The string to find and replace.

Param
replaceWith
replaceWith

The replacement string.

Returns

The number of occurences that were found and replaced.

Example
Code Block
csharp
csharp
titleC#

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

          //--- Update a copyright
          //--- Search for: (c) or the copyright symbol in ASCII, one or more whitespace characters,
          //--- four digits, and then any number of characters followed by 'Inc.'
          //--- Replace matches with '(c) 2008 SoftArtisans, Inc.'
          doc.SearchAndReplace("(\(c\)|\xA9)\s+[0-9]{4}\s+SoftArtisans, Inc\.", "(c) 2008 SoftArtisans, Inc.");
        
Code Block
vb.net
vb.net
titlevb.net

          Dim app As New WordApplication()
          Dim doc As Document = app.Open("C:\myDoc.doc")

          '--- Update a copyright
          '--- Search for: (c) or the copyright symbol in ASCII, one ore more whitespace characters,
          '--- four digits, and then any number of characters followed by 'Inc.'
          '--- Replace matches with '(c) 2008 SoftArtisans, Inc.'
          doc.SearchAndReplace("(\(c\)|\xA9)\s+[0-9]{4}\s+SoftArtisans, Inc\.", "(c) 2008 SoftArtisans, Inc.")