Is there a way to detect the encoding of a stream in vb.net?
I would like to know the way a stream or a string is encoded before converting it. If a string is not utf-8 i开发者_如何学Ct would be converted to utf-8.
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).
精彩评论