Free Support Forum - aspose.com

How to give New Line Character in word

HI

I have used the following for find and replace

string address="Address1 Address2 Address3";

objWordDoc.Range.Replace(#Address#, address, false, false);

The result of above is like

Address1 Address2 Address3

But my requirement is like,the result should display like

Address1

Address2

Address3

Can i use any newline characters in the string "address",some thing like "\n" in .net .

ex: Address1\nAddress2\nAdress3

Or any other option to achieve my requirement

Regards

Ajeesh M J

Hi Ajeesh,

Thanks for your inquiry. In your case, I suggest you please implement IReplacingCallback Interface and use the following code snippet to achieve your requirements.

Moreover, please check the code examples shared at following documentation links for your kind reference. Hope this helps you. Please let us know if you have any more queries.
http://www.aspose.com/docs/display/wordsnet/Find+and+Replace+Overview
http://www.aspose.com/docs/display/wordsnet/How+to+Find+and+Highlight+Text


Document doc = new Document(MyDir + "in.docx");

ReplaceTest obj = new ReplaceTest();

obj.relaceText = "Address1 Address2 Address3";

doc.Range.Replace(new Regex("#Address#"), obj, false);

doc.Save(MyDir + "out.docx");

private class ReplaceTest : IReplacingCallback

{

public string relaceText = "";

ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)

{

DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);

builder.MoveTo(e.MatchNode);

foreach (string address in relaceText.Split(new Char[] { ' ' }))

{

builder.Writeln(address);

}

e.Replacement = "";

return ReplaceAction.Replace;

}

}