Determine a string's encoding in C#

前端 未结 9 1946
小鲜肉
小鲜肉 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:47

    The SimpleHelpers.FileEncoding Nuget package wraps a C# port of the Mozilla Universal Charset Detector into a dead-simple API:

    var encoding = FileEncoding.DetectFileEncoding(txtFile);
    

提交回复
热议问题