使用控制字符
Contents
[
Hide
]
Microsoft Word文档可能包含具有特殊含义的各种字符。 通常它们用于格式化目的,而不是在正常模式下绘制。 如果单击位于标准工具栏上的显示/隐藏格式标记按钮,则可以使它们可见。
有时您可能需要在文本中添加或删除字符。 例如,当从文档中以编程方式获取文本时,Aspose.Words保留了大部分控制字符,因此如果您需要使用此文本,您可能应该删除或替换字符。
ControlChar类是表示文档中经常遇到的控制字符的常量的存储库。 它提供相同常量的char和string版本。 例如,stringLineBreak和charLineBreakChar具有相同的值。
每当要处理控制字符时,都使用此类。
下面的代码示例演示如何使用控制字符:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(UseControlCharacters.class); | |
// Open the document. | |
Document doc = new Document(); | |
DocumentBuilder builder = new DocumentBuilder(doc); | |
builder.write("This is First Line"); | |
builder.write(ControlChar.CR); | |
builder.write("This is Second Line"); | |
builder.write(ControlChar.CR_LF); | |
doc.save(dataDir + "output.doc"); |