【问题标题】:Reading unknown-encoded text files in Adobe AIR在 Adob​​e AIR 中读取未知编码的文本文件
【发布时间】:2016-04-09 23:50:59
【问题描述】:

我有一个 Adob​​e AIR 应用程序,用户可以在其中处理文件系统中的文本文件。我一直假设 UTF-8,但如果文本文件采用其他编码(例如 iso-8859-1 或 iso-2022-kr),我应该如何确定(最好的猜测)编码类型文本文件,以便我可以将内容读入字符串?

FileStream.readMultiByte 支持an intimidating range of types

【问题讨论】:

  • 我可以尝试 File.systemCharset 但不能保证该文件是由运行我的应用程序的机器创建的。如果我可以首先确定该文件不是 UTF-8,那可能是可接受的后备。
  • 这里是关于 PHP 的 mb_detect_encoding 的讨论,但是 AS3 没有类似的东西(我可以找到官方或用户编写的)php.net/manual/en/function.mb-detect-encoding.php

标签: text encoding utf-8 air


【解决方案1】:

您可以尝试通过查看文件是否有标题来猜测,例如 BOM。但你永远不会百分百确定。

看看其他答案:

How to detect the encoding of a file?

How can I detect the encoding/codepage of a text file

编辑:也许这是一种猜测方法,它不在 AS3 中,但它可以提供帮助:Simple class to automatically detect text file encoding, with English-biased "best guess" heuristic based on byte patterns in the absence of BOM.

此外,如果它是您应用中的一个选项,您可以使用 UTF-8 并让用户以他们选择的另一种编码预览文本。

【讨论】:

  • 我将尝试转换并使用您链接的 C# 类来确定 UTF-8/16/32/BOM/no-BOM 然后回退到 File.systemCharset 并让用户从列表。很好的建议 - 谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-25
  • 2010-09-25
  • 1970-01-01
相关资源
最近更新 更多