Invalid characters in File.ReadAllText

后端 未结 4 679
离开以前
离开以前 2020-12-06 17:52

I\'m calling File.ReadAllText() in a program designed to format some files that I have.

Some of these files contain the ® (174) symbol. H

4条回答
  •  感动是毒
    2020-12-06 18:06

    The character you are reading is the Replacement character

    used to replace an incoming character whose value is unknown or unrepresentable in Unicode compare the use of U+001A as a control character to indicate the substitute function

    http://www.fileformat.info/info/unicode/char/fffd/index.htm

    You are getting this because the actual encoding of the file does not match the encoding your program expects.

    By default ReadAllText expects UTF-8. It is encountering a byte sequence that does not represent a valid UTF-8 character, so replacing it with the Replacement character.

提交回复
热议问题