有没有办法检测 vb.net 中流的编码?

发布于 2024-12-03 10:36:26 字数 53 浏览 5 评论 0原文

我想知道转换流或字符串之前的编码方式。如果字符串不是 utf-8,它将被转换为 utf-8。

I would like to know the way a stream or a string is encoded before converting it. If a string is not utf-8 it would be converted to utf-8.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[浮城] 2024-12-10 10:36:26

您可以使用 WinAPI 函数 IsTextUnicode 它使用启发式来猜测正确的编码。请注意,这可能会严重错误

最好的方法是不接受没有有关其编码的外部信息的流,否则接受内部信息(例如 BOM 或带有编码信息的 HTML 元标记)。

You could use the WinAPI function IsTextUnicode which uses a heuristic to guess the proper encoding. Note that this can go hilariously wrong.

The best way is not to accept streams without external information about their encoding, and failing that, internal information (such as a BOM, or a HTML meta-tag with encoding information).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文