Encoding

LoadOptions.Encoding property

获取或设置用于加载 HTML、TXT 或 CHM 文档的编码(如果未在文档中指定编码)。 可以是无效的 默认为无效的.

public Encoding Encoding { get; set; }

评论

此属性仅在加载 HTML、TXT 或 CHM 文档时使用。

如果文档中未指定编码,并且此属性无效的,则系统将尝试自动检测编码。

例子

展示如何设置打开文档的编码。

LoadOptions loadOptions = new LoadOptions
{
    Encoding = Encoding.ASCII
};

// 在传递 LoadOptions 对象的同时加载文档,然后验证文档的内容。
Document doc = new Document(MyDir + "English text.txt", loadOptions);

Assert.True(doc.ToString(SaveFormat.Text).Contains("This is a sample text in English."));

也可以看看