// 替换字符串中与钦点的合营形式一致的字符串
[sqlfunction(isdeterministic = true, isprecise = true)] public static
sqlstring regexreplace(sqlstring expression, sqlstring pattern,
sqlstring replacement) { return new
sqlstring(regex.replace(expression.tostring(), pattern.tostring(),
replacement.tostring())); }

/// Inserts the new run just after the specified run.

t-sql 正则表明式制造程序集 clrregexclass.cs,并行使
c:windowsmicrosoft.netframeworkv2.0.50727csc.exe /target:library
clrregexclass.cs 编写翻译为 clrregexclass.dll 文件。using system;using
system.data;using system.data.sqlclient;using system.data.sqltypes;using
microsoft.sqlserver.server;using system.text.regularexpressions;

// For complete examples and data files, please go to
https://github.com/aspose-words/Aspose.Words-for-.NET

// 提取字符串中与内定的极其格局一致的字符串
[sqlfunction(isdeterministic = true, isprecise = true)] public static
sqlstring regexsubstring(sqlstring expression, sqlstring pattern,
sqlint32 position, sqlint32 occurrence) { if
(expression.tostring().length position) return new sqlstring(); if
(position = 0) position = 1; if (occurrence = 0) occurrence = 1;

/// </summary>

public partial class regexp{//
验证字符串中是否含有与钦点的万分格局一致的字符串
[sqlfunction(isdeterministic = true, isprecise = true)] public static
sqlboolean regexismatch(sqlstring expression, sqlstring pattern) {
return new sqlboolean(regex.ismatch(expression.tostring(),
pattern.tostring())); }

{

match m = regex.match(expression.tostring().substring((int) position –
1),pattern.tostring()); for (int i = 1; i (int)occurrence; i++) { m =
m.nextmatch(); if (!m.success) return new sqlstring(); }

run.Font.HighlightColor = Color.Yellow;

return new sqlstring(m.tostring()); }首页 1 2 末页

ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)

string fileName = “TestFile.doc”;

view
raw
Examples-CSharp-Programming-Documents-Find-Replace-FindAndHighlight-SplitRun.cs
hosted with ❤ by GitHub

// Save the output document.

/// Splits text of the specified run into two runs.

if ((currentNode != null) && (remainingLength > 0))

FindReplaceOptions options = new FindReplaceOptions();

foreach (Run run in runs)

}

currentNode = SplitRun((Run)currentNode, e.MatchOffset);

}

}

Regex regex = new Regex(“your document”, RegexOptions.IgnoreCase);

private static Run SplitRun(Run run, int position)

// Now highlight all runs in the sequence.

Run (Run.Text = “!”)

do

(currentNode.GetText().Length <= remainingLength))

string dataDir = RunExamples.GetDataDir_FindAndReplace();

// The first (and may be the only) run can contain text before the
match,

Document doc = new Document(dataDir + fileName);

Run afterRun = (Run)run.Clone(true);

/// </summary>

// Select the next Run node.

/// This is called during a replace operation each time a match is
found.

}

currentNode = currentNode.NextSibling;

private class MyReplaceEvaluator : IReplacingCallback

}

{

doc.Range.Replace(regex, “”, options);

// Find all runs that contain parts of the match string.

view
raw
Examples-CSharp-Programming-Documents-Find-Replace-FindAndHighlight-ReplaceEvaluatorFindAndHighlight.cs
hosted with ❤ by GitHub

mMatchNumber++;

{

return ReplaceAction.Skip;

run.ParentNode.InsertAfter(afterRun, run);

{

options.Direction = FindReplaceDirection.Backward;

if (e.MatchOffset > 0)

while ((currentNode != null) && (currentNode.NodeType != NodeType.Run));

// The path to the documents directory.

}

This article provides a solution designed to handle the described case –
if necessary it collects the word (or phrase) from several runs, while
skipping non-run nodes.
The Code
The sample code will open a document and find any instance of the text
“your document”. A replace handler is set up to handle the logic to be
applied to each resulting match found. In this case the resulting runs
are split around the txt and the resulting runs highlighted. Below
example finds and highlights all instances of a particular word or a
phrase in a Word document. You can download template file of this
example from
here.

private int mMatchNumber;

Example 1: Replace One Word with Another
Shows how to replace all occurrences of word “sad” to “bad”. You can
download template file of this example from
here.

Author

发表评论

电子邮件地址不会被公开。 必填项已用*标注