'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.DrawingImportsSystem.LinqImportsSystem.Collections.GenericImportsSystem.Text.RegularExpressionsImportsGrapeCity.Documents.Word '' This sample shows how to replace all occurrences of a string'' in a DOCX document (see JsFrameworkExcerpt) using the'' RangeBase.Replace extension method provided by the'' RangeBaseFindReplaceExtensions class.'' This sample Is similar to ReplaceText, with the addition of'' also updating the replacement's style.PublicClassReplaceTextFmtPublicFunctionCreateDocx() AsGcWordDocument'' The document to replace text in:Dim path = IO.Path.Combine("Resources", "WordDocs", "JsFrameworkExcerpt.docx")'' The text to findConsttFind = "javascript"'' The replacementConsttRepl = "ArabicaScroll"'' Name for the replacement's style:ConststyleName = "my new style" '' Load the source document:Dim doc = NewGcWordDocument() doc.Load(path) '' The New style for replaced text:Dim style = doc.Styles.Add(styleName, StyleType.Character) style.Font.Color.RGB = Color.Red '' Replace text And replacements' style:Dim nreplacements = doc.Body.Replace(tFind, tRepl,NewFindReplaceOptions(doc) With { .IgnoreCase = True, .ReplacedCallback = Sub(args_) args_.ReplacedRange.Runs.ToList().ForEach(Sub(r_) r_.Style = style) }) '' Add a note at the end of the document doc.Body.Paragraphs.Add($"DsWord replaced {nreplacements} occurrences of '{tFind}' with '{tRepl}' on {Util.TimeNow():R}.") '' DoneReturn docEndFunctionEndClass