ContentRangeFind(String) Method |
Namespace: SautinSoft.DocumentAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.11.20
Syntax public IEnumerable<ContentRange> Find(
string text
)
Public Function Find (
text As String
) As IEnumerable(Of ContentRange)
Parameters
- text String
- The text which should be searched for.
Return Value
IEnumerableContentRange
All
ContentRanges which contain the specified text.
Exceptions Exception | Condition |
---|
ArgumentException |
Argument text can't be null or empty.
|
Example See Developer Guide: Find and replace a text using ContentRange
Find and replace a text using ContentRange in C#
using System.IO;
using SautinSoft.Document;
using System.Linq;
using System.Text.RegularExpressions;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
FindAndReplace();
}
public static void FindAndReplace()
{
string loadPath = @"..\..\..\critique.docx";
DocumentCore dc = DocumentCore.Load(loadPath);
Regex regex = new Regex(@"bean", RegexOptions.IgnoreCase);
foreach (ContentRange item in dc.Content.Find(regex).Reverse())
{
item.Replace("Joker");
}
string savePath = "Replaced.pdf";
dc.Save(savePath, new PdfSaveOptions());
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(loadPath) { UseShellExecute = true });
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(savePath) { UseShellExecute = true });
}
}
}
Find and replace a text using ContentRange in VB.Net
Imports System.IO
Imports SautinSoft.Document
Imports System.Linq
Imports System.Text.RegularExpressions
Module Sample
Sub Main()
FindAndReplace()
End Sub
Sub FindAndReplace()
Dim loadPath As String = "..\..\..\critique.docx"
Dim dc As DocumentCore = DocumentCore.Load(loadPath)
Dim regex As New Regex("bean", RegexOptions.IgnoreCase)
For Each item As ContentRange In dc.Content.Find(regex).Reverse()
item.Replace("Joker")
Next item
Dim savePath As String = "Replaced.pdf"
dc.Save(savePath, New PdfSaveOptions())
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(loadPath) With {.UseShellExecute = True})
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(savePath) With {.UseShellExecute = True})
End Sub
End Module
See Also