在C#中确定一个字符串的编码 [英] Determine a string's encoding in C#

查看:93
本文介绍了在C#中确定一个字符串的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个文件名字符串,但是我不知道它是否编码在<罢工> Unicode UTF-16或系统默认编码,如何找出?

解决方案

Utf8Checker是纯粹的托管代码中的简单类。
http://utf8checker.codeplex.com



注意:如已经指出的,确定编码只对字节流有意义。如果你有一个字符串,那么它已经被编码了,他们已经知道或猜测了编码的方式,首先得到了字符串。


Is there any way to determine a string's encoding in C#?

Say, I have a filename string, but I don't know if it is encoded in Unicode UTF-16 or the system-default encoding, how do I find out?

解决方案

Check out Utf8Checker it is simple class that does exactly this in pure managed code. http://utf8checker.codeplex.com

Notice: as already pointed out "determine encoding" makes sense only for byte streams. If you have a string it is already encoded from someone along the way who already knew or guessed the encoding to get the string in the first place.

这篇关于在C#中确定一个字符串的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆