Delphi - 获取给定文件的编码
我读过这个问题,我认为它会给我我所追求的:
我想知道是否有其他方法来获取文件编码,不使用D2006 中的 Mozilla i18n 组件?我无法使用其他 3d 方组件。
我已阅读原始问题的所有答案,但我无法使用提供的接口,因为客户端不接受该 dll 的部署:
- 第一个答案 - https://stackoverflow.com/a/373103/368364 - 没有结论。
- 第二个答案 - http://www.siao2.com/2007/04/22 /2239345.aspx - 关于并阅读评论会给你一个线索!
- 第三个答案 - 当 BOM(字节顺序标记)丢失时,如何最好地猜测编码? - 用户选择编码。
原始问题中提供的一些链接已失效,没有一个链接能解决我的问题,即:
如何在不使用第三方组件的情况下获取文件编码?
I have read this question which I thought would give me what I was after:
How Can I Best Guess the Encoding when the BOM (Byte Order Mark) is Missing?
I would like to know if there is another way to get the file encoding, without using Mozilla's i18n component in D2006? I can not use other 3d party components.
I have read the all the answers from original question, and I can not use the interface provided because the client doesn't accept the deployment of that dll:
- first answer - https://stackoverflow.com/a/373103/368364 - nothing conclusive.
- second answer - http://www.siao2.com/2007/04/22/2239345.aspx - regarding and reading the comments give you a clue!
- third answer - How Can I Best Guess the Encoding when the BOM (Byte Order Mark) is Missing? - user choice the encoding.
Some of the links provided in the original question are dead, and none address my problem, which is:
How to get the file encoding without using 3rd party components?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会首先查找 BOM,如果未找到,则调用 IsTextUnicode。但请注意,没有任何方法是万无一失的。
I would look for a BOM first and if one is not found call IsTextUnicode. But beware that no method is foolproof.
确定文件的编码似乎是有问题的。某些 UTF8 文件似乎没有 BOM。这似乎有效:
是否有更好的方法。我知道这个解决方案不是很优雅。
Determining the encoding of a file seems to be problematic. It appears that some of the UTF8 files do not have a BOM. This appears to work:
Is there a better approach. I know this solution isn't very elegant.