有没有办法检测 vb.net 中流的编码?
我想知道转换流或字符串之前的编码方式。如果字符串不是 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 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).