Home > Net >  Read the code file
Read the code file

Time:04-20

The problem is this:
A gb2312 encoding of the text files, each pair of double quotes contains a string value, under the condition of the content is garbled how to correctly identify the double quotes?
So I began to read:
File. ReadAllLines (filePath, Encoding. GetEncoding (Encoding));
Unexpected is below this kind of circumstance:
Such as in the first 10 bytes can find corresponding characters in the ASCII character set or gb character set, one of the first byte is a former double quotes, here everything is normal, and 11 bytes is not ASCII characters, nor gb the first byte of the characters, at this time due to the gb2312 encoding for each character of two bytes, ReadAllLines function will get 11 and 12 bytes as a character processing, returns a '? 'character, if character after just 12 double quotation marks, the double quotation marks will be swallowed, what file reading way can avoid this kind of situation? (don't want to go to byte read files a bytes in a byte to identify...
I think there will be a solution, because with vs code to open this file, gb2312 only 11 characters will be '? 'and 12 characters in double quotes will be retained, so want to talk to you pick a classics, how to achieve the result of vs code

CodePudding user response:

Set is arguably the second parameter Encoding should not bias,
  •  Tags:  
  • C#
  • Related