# GrapeCity.Documents.Word.RangeBaseFindReplaceExtensions.Replace

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="GrapeCity_Documents_Word_RangeBaseFindReplaceExtensions_Replace_" data-uid="GrapeCity.Documents.Word.RangeBaseFindReplaceExtensions.Replace*">Replace Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="GrapeCity_Documents_Word_RangeBaseFindReplaceExtensions_Replace_" data-uid="GrapeCity.Documents.Word.RangeBaseFindReplaceExtensions.Replace*"></a>
<h4 id="GrapeCity_Documents_Word_RangeBaseFindReplaceExtensions_Replace_GrapeCity_Documents_Word_RangeBase_System_String_System_String_GrapeCity_Documents_Word_FindReplaceOptions_" data-uid="GrapeCity.Documents.Word.RangeBaseFindReplaceExtensions.Replace(GrapeCity.Documents.Word.RangeBase,System.String,System.String,GrapeCity.Documents.Word.FindReplaceOptions)">Replace(RangeBase, string, string, FindReplaceOptions)</h4>
<div class="markdown level1 summary"><p>In the current range, searches for a specified <code class="paramref">findPattern</code>,
and replaces it with a provided <code class="paramref">replaceText</code>,
using specified <code class="paramref">options</code>.</p>
<p>
The <code class="paramref">findPattern</code> can contain regular expressions 
(use <a class="xref" href="GrapeCity.Documents.Word.FindOptions.RegularExpressions.html#GrapeCity_Documents_Word_FindOptions_RegularExpressions">RegularExpressions</a> to control this).
</p>
<p>
The following special tokens can be used in the <code class="paramref">findPattern</code>
and in the <code class="paramref">replaceText</code> regardless of whether regex are on or off:
<ul><li><span class="term">&amp;p</span>end of paragraph</li><li><span class="term">&amp;l</span>manual line break</li><li><span class="term">&amp;m</span>page break</li><li><span class="term">&amp;b</span>section break</li></ul>

<p>
To search for text with certain formatting, use <code class="paramref">options</code>
and set the <a class="xref" href="GrapeCity.Documents.Word.FindOptions.FormattingOptions.html#GrapeCity_Documents_Word_FindOptions_FormattingOptions">FormattingOptions</a> on it accordingly.
</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static int Replace(this RangeBase searchRange, string findPattern, string replaceText, FindReplaceOptions options = null)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Shared Function Replace(searchRange As RangeBase, findPattern As String, replaceText As String, Optional options As FindReplaceOptions = Nothing) As Integer</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="GrapeCity.Documents.Word.RangeBase.html">RangeBase</a></td>
      <td><span class="parametername">searchRange</span></td>
      <td><p>The current range.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">findPattern</span></td>
      <td><p>The search pattern. May contain regular expressions, or be an empty string.
<p>If empty, the search will be for any text with formatting that matches the <a class="xref" href="GrapeCity.Documents.Word.FindOptions.FormattingOptions.html#GrapeCity_Documents_Word_FindOptions_FormattingOptions">FormattingOptions</a>
passed in <code class="paramref">options</code>.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.string">string</a></td>
      <td><span class="parametername">replaceText</span></td>
      <td><p>The replacement text.
<p>If empty, the found text will be removed.
<a class="xref" href="GrapeCity.Documents.Word.FindReplaceOptions.ReplacingCallback.html#GrapeCity_Documents_Word_FindReplaceOptions_ReplacingCallback">ReplacingCallback</a> can still be used to provide a replacement string.
</p>
If null, no replacement will occur, but
<a class="xref" href="GrapeCity.Documents.Word.FindReplaceOptions.ReplacingCallback.html#GrapeCity_Documents_Word_FindReplaceOptions_ReplacingCallback">ReplacingCallback</a> and <a class="xref" href="GrapeCity.Documents.Word.FindReplaceOptions.ReplacedCallback.html#GrapeCity_Documents_Word_FindReplaceOptions_ReplacedCallback">ReplacedCallback</a>
will still be called.
</td>
    </tr>
    <tr>
      <td><a class="xref" href="GrapeCity.Documents.Word.FindReplaceOptions.html">FindReplaceOptions</a></td>
      <td><span class="parametername">options</span></td>
      <td><p>The search and replace options.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><p>The number of replaced occurrences.</p>
</td>
    </tr>
  </tbody>
</table>
</div>
