Issue in formating when using Range.Replace Method

Hi
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);
doc.Save("D:/temp/Out.docx");
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
            if (value>= 0)
                e.Replacement = value.ToString(); //"ReplaceTitleString";
            else
                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.