FindReplaceOptions
Содержание
[
Скрывать
]ReplacerContext.FindReplaceOptions property
Параметры поиска/замены.
public FindReplaceOptions FindReplaceOptions { get; }
Примеры
Показывает, как заменить строку регулярным выражением в документе, используя контекст.
// Существует несколько способов заменить строку регулярным выражением в документе:
string doc = MyDir + "Footer.docx";
Regex pattern = new Regex("gr(a|e)y");
string replacement = "lavender";
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
Replacer.Create(replacerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.ReplaceContextRegex.docx")
.Execute();
Показывает, как заменить строку в документе, используя контекст.
// Существует несколько способов заменить строку в документе:
string doc = MyDir + "Footer.docx";
string pattern = "(C)2006 Aspose Pty Ltd.";
string replacement = "Copyright (C) 2024 by Aspose Pty Ltd.";
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
Replacer.Create(replacerContext)
.From(doc)
.To(ArtifactsDir + "LowCode.ReplaceContext.docx")
.Execute();
Показывает, как заменить строку в документе, используя документы из потока с использованием контекста.
// Существует несколько способов заменить строку в документе, используя документы из потока:
string pattern = "(C)2006 Aspose Pty Ltd.";
string replacement = "Copyright (C) 2024 by Aspose Pty Ltd.";
using (FileStream streamIn = new FileStream(MyDir + "Footer.docx", FileMode.Open, FileAccess.Read))
{
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceContextStream.docx", FileMode.Create, FileAccess.ReadWrite))
Replacer.Create(replacerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}
Показывает, как заменить строку регулярным выражением в документе, используя документы из потока с использованием контекста.
// Существует несколько способов заменить строку регулярным выражением в документе, используя документы из потока:
Regex pattern = new Regex("gr(a|e)y");
string replacement = "lavender";
using (FileStream streamIn = new FileStream(MyDir + "Replace regex.docx", FileMode.Open, FileAccess.Read))
{
ReplacerContext replacerContext = new ReplacerContext();
replacerContext.SetReplacement(pattern, replacement);
replacerContext.FindReplaceOptions.FindWholeWordsOnly = false;
using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ReplaceContextStreamRegex.docx", FileMode.Create, FileAccess.ReadWrite))
Replacer.Create(replacerContext)
.From(streamIn)
.To(streamOut, SaveFormat.Docx)
.Execute();
}
Смотрите также
- class FindReplaceOptions
- class ReplacerContext
- пространство имен Aspose.Words.LowCode
- сборка Aspose.Words