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

Free Support Forum - aspose.com

Issue in formating when using Range.Replace Method


I have the following variable in my Template document

~#MyVariable~# Am using

"Range.Replace" to replace the variable with value from database.Now my issue is,if my value from database is negative then it should display with in brackets ie

if value=-13 then it should display as (13)

Hi Ajeesh,

Thanks for your inquiry. In your case, i will suggest you following code snippet:

Document doc = new Document("D:/temp/input.docx");

Regex regex = new Regex(@"(?~#(.*?)~#%)", RegexOptions.IgnoreCase);

doc.Range.Replace(regex, new InsertDocumentAtReplaceHandler(), true);


public class InsertDocumentAtReplaceHandler : IReplacingCallback


ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)


String title = e.Match.Groups["title"].Value.Trim();

//Pass title variable to interpret translator

Int32 value = //get it from database


e.Replacement = value.ToString();//"ReplaceTitleString";


e.Replacement = "(" + value.ToString() + ")";

e.Replacement = i.ToString();//"ReplaceTitleString";

return ReplaceAction.Replace;



I hope this will help. In case of any ambiguity, please let me know.