How can I detect the encoding/codepage of a text file

后端 未结 20 1388
梦如初夏
梦如初夏 2020-11-21 22:42

In our application, we receive text files (.txt, .csv, etc.) from diverse sources. When reading, these files sometimes contain garbage, because the

20条回答
  •  情歌与酒
    2020-11-21 23:15

    As addon to ITmeze post, I've used this function to convert the output of C# port for Mozilla Universal Charset Detector

        private Encoding GetEncodingFromString(string codePageName)
        {
            try
            {
                return Encoding.GetEncoding(codePageName);
            }
            catch
            {
                return Encoding.ASCII;
            }
        }
    

    MSDN

提交回复
热议问题