{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 {{[\^$.|?*+(){\}}}. {excerpt} {signature:C#} public virtual int SearchAndReplace(System.String search, System.String replaceWith) {signature} {signature:vb.net} Public Overridable Function SearchAndReplace(ByVal search As String, ByVal replaceWith As String) As Integer {signature} {parameters} {param:search}The string to find and replace. {param} {param:replaceWith}The replacement string. {param} {returns}The number of occurences that were found and replaced. {returns} {example}{code:csharp|title=C#} 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} {code:vb.net|title=vb.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.") {code} {example} |