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

Free Support Forum - aspose.com

Soft line break converted to newline instead of vertical tab when saving as text file

Hi,

I have a Word document that contains a paragraph with a soft line break. When I save this document as text, I expect this soft line break to be converted to a vertical tab \v but it is instead converted to a a line break \n\r.

Is there an option to modify this behavior and get a \v instead of a \r\n?

Thanks

See attached project.

I use Aspose.Words 16.4 for .Net

Hi Franz-Josef,

Thanks for your inquiry. Could you please share your expected output text file here for our reference? We will then provide you more information about your query along with code.

Hi Tahir,

See the attached file. It contains a vertical tab (0x0b) between the words Hello and World.

Hi Franz-Josef,

Thanks for your inquiry. Please refer to the following article:
Find and Replace

Please use Range.Replace method as shown below to replace line break with 0x0b. Hope this helps you.

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

doc.Range.Replace(ControlChar.LineBreak, "" + (char)0x0b, new FindReplaceOptions());

doc.Save(MyDir + "17.3.0.txt");

Hi Tahir,

The thing is, your code also converts the \n\r at the end of the text. But I guess when using your code, I can simply revert that last vertical tab back to a \n\r.

Thanks,

Christophe

Hi Franz-Josef,

Thanks for your inquiry. The shared code example replaces the line break with 0x0b. Please refer to the following article:
Aspose.Words Document Object Model

Your input document have one Section. A minimal valid section needs to have Body with one Paragraph. The last paragraph of document contains the section break. Could you please share how are you checking the output text file? We have not found any issue with output text file when it is opened in notepad.

Hi Tahir,

I use the HxD Hex Editor to see what is contained in the text file.

Hi Franz-Josef,

Thanks for sharing the detail. The last node of document is paragraph break. So, you are getting it in output document. In your case, we suggest you please IReplacingCallback interface as shown below. Hope this helps you.

Moreover, please check the code examples shared in following article.

Find and Replace


class
ReplaceEvaluator : IReplacingCallback

{

///

/// This method is called by the Aspose.Words find and replace engine for each match.

///

ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)

{

if (e.MatchNode.GetText().Contains(ControlChar.LineBreak))

return ReplaceAction.Replace;

return ReplaceAction.Skip;

}

}

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

FindReplaceOptions findreplace = new FindReplaceOptions();

findreplace.ReplacingCallback = new ReplaceEvaluator();

doc.Range.Replace(ControlChar.LineBreak, "" + (char)0x0b, findreplace);

doc.Save(MyDir + "17.3.0.txt");

Hi Tahir,

This interface is interesting, thanks for letting me know about it, I’ll play a bit with it.

Best regards,

Christophe