We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Word Range Replace


We have a problem about " wordDoc.Range.Replace(regex, feval, true); " code. In same two docs have same tags, but "correct.doc" doc find and replace this <@SKT> tag correctly. But "incorrect.doc" doc find without ">" character.

Therefore ; in replace function, "incorrect.doc" doc doesn't replace ">" character.

Our code:

DocumentBuilder builder = new DocumentBuilder(wordDoc);
Regex regex = new Regex("\\<@", RegexOptions.IgnoreCase);
FindEval feval = new FindEval();
wordDoc.Range.Replace(regex, feval, true);
foreach (Run run in feval.nodes)
if (!HasTag(tagList, run.Text))
tagList += run.Text+"|";

if (tagList != "") tagList = tagList.Substring(0, tagList.Length - 1);
Hi Ahmet,

Thanks for your query. All text of the document is stored in runs of text. It is possible that two Run node have text <@SKT>. E.g '<@SKT' in one Run node and '>' in second Run node.

In your case, I suggest you please call Document.JoinRunsWithSameFormatting method after loading the document. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "Incorrect.doc");


Regex regex = new Regex("\\<@(.*?)\\>", RegexOptions.IgnoreCase);

FindEval obj = new FindEval();

doc.Range.Replace(regex, obj, true);

foreach (Run run in obj.nodes)