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

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

问题描述

有没有办法在 C# 中确定字符串的编码?

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

比如说,我有一个文件名字符串,但我不知道它是用 Unicode UTF-16 编码还是系统默认编码,我怎么知道?

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?

推荐答案

查看 Utf8Checker,它是一个简单的类,它在纯托管代码中执行此操作.http://utf8checker.codeplex.com

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天全站免登陆