Determine a string's encoding in C#

前端 未结 9 2032
小鲜肉
小鲜肉 2020-11-22 14:54

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

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 15:41

    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.

提交回复
热议问题