aspose.words-查找并替换功能 - 用新的line字符查找文本
我正在尝试使用Aspose.words(版本22.4)在Word文档中搜索和替换以下文本。但是,Aspose替换函数无法在文档中找到并替换文本。
[服务等待期:
[[[30天]主动连续服务。]
我正在使用以下代码,
rule.MergeField = "[SERVICE WAITING PERIOD:\r\n[[30 days] of Active continuous service.]]";
mergedDocument.Range.Replace(rule.MergeField.Replace("\n", "&l").Replace("\r", "&p"),
"abc", new Aspose.Words.Replacing.FindReplaceOptions()
{ MatchCase = false, FindWholeWordsOnly = false });
我还尝试替换\ n
,\ r
在带有Aspose控制字符的文字中,没有任何运气。 有没有人尝试过这样的事情,或者迅速支持这种搜索文本?
感谢您的帮助。
06/09更新
用Alexey建议使用& p替换\ r \ n
。太感谢了。需要在元理论中提供帮助,以使下面的文本迅速迅速。
\ r
示例文本 - 损失日期的年龄\原始福利金额\ r [年龄70-74] \ r [65%] \ r [年龄75-- 79] \ r [45%] \ r [年龄80-84] \ r [30%] \ r [年龄85岁或以上] \ r [15%] \ r
单词等效 -
\ t(tab)
示例文本 - 覆盖\ tperCentage of \ tpercentage of \ r \ r \ n \ tfour tfour tfour \ t [100% ] \ r \ n \ tthree肢体\ t [75%] \ r \ n \ ttwo四肢\ t [66.67%] \ r \ n \ n \ tone limb \ t [50%] \ r \ r \ n
更新06/15
我试图用\ t搜索并替换文本,但它与以下代码不起作用。
rule.MergeField = "Class II:\t\tWhile participating in game, please make sure to wear your helmets.";
mergedDocument.Range.Replace(rule.MergeField.Replace("\r\n", "&p").Replace("\t", ControlChar.Tab),
finalValue.Replace("\r\n", "&p").Replace("\t", "&l"), new Aspose.Words.Replacing.FindReplaceOptions()
{ MatchCase = false, FindWholeWordsOnly = false });
I am trying to search and replace the below text in a word document using Aspose.Words (Version 22.4). But, the Aspose replace function is not able to find and replace the text in the document.
[SERVICE WAITING PERIOD:
[[30 days] of Active continuous service.]]
I am using the below code, where
rule.MergeField = "[SERVICE WAITING PERIOD:\r\n[[30 days] of Active continuous service.]]";
mergedDocument.Range.Replace(rule.MergeField.Replace("\n", "&l").Replace("\r", "&p"),
"abc", new Aspose.Words.Replacing.FindReplaceOptions()
{ MatchCase = false, FindWholeWordsOnly = false });
I have also tried replacing the \n
, \r
in text with the Aspose Control Characters without any luck.
Has anyone tried something like this or does aspose support such search text?
Thank you for your help.
06/09 Updates
Replacing \r\n
with &p as suggested by Alexey worked. thank you so much. Need help on the metacharacters for aspose for below text.
\r
Example text - Age at Date of Loss\rPercent of Original Benefit Amount\r[Age 70-74]\r[65%]\r[Age 75-79]\r[45%]\r[Age 80-84]\r[30%]\r[Age 85 or over]\r[15%]\r
Word equivalent -
\t (Tab)
Example text - COVERED LOSS OF USE OF\tPERCENTAGE OF COVERAGE AMOUNT\r\n\tFour Limbs\t[100%]\r\n\tThree Limbs\t[75%]\r\n\tTwo Limbs\t[66.67%]\r\n\tOne Limb\t[50%]\r\n
UPDATES 06/15
I tried to search and replace the text with \t but it does not work with below code.
rule.MergeField = "Class II:\t\tWhile participating in game, please make sure to wear your helmets.";
mergedDocument.Range.Replace(rule.MergeField.Replace("\r\n", "&p").Replace("\t", ControlChar.Tab),
finalValue.Replace("\r\n", "&p").Replace("\t", "&l"), new Aspose.Words.Replacing.FindReplaceOptions()
{ MatchCase = false, FindWholeWordsOnly = false });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该用
& p
metacharacter替换序列\ r \ n
,以匹配document
中的段落中断。例如,请参见以下代码:& l
metacharacter代表软件间断,即\ v
,您可以使用shift+ shift+ shift+ shift+输入
更新:
您可以在匹配字符串和替换中使用
\ t
字符。您突出显示的另一个角色是细胞中断。您不能替换它。 MS Word中的表单元总是包含一个段落,突出显示的字符是单元格中最后一个段落的末尾。它不能删除。
You should replace a sequence
\r\n
with&p
metacharacter to match paragraph break in theDocument
. For example see the following code:&l
metacharacter represent a soft line break, which is\v
, you can insert such break in MS Word usingShift+Enter
UPDATE:
You can use
\t
character in your match string and replacement.The other character you have highlighted is cell break. You cannot replace it. Table cell in MS Word always contain a paragraph and the highlighted character is the end of the last paragraph in the cell. It cannot be removed.