Finding the encoding type in Mac is much easier.
What is the encoding of a text file. Byte bytes FileReadAllBytesfilename. If you open a txt file in notepadexe and click save as it will tell you what file encoding that file is. When VS Code saves a file it uses a text encoding to decide what bytes each character becomes.
However it might be an ISO-8859-1 file which happens to start with the. To get the exact encoding you need the file executable that is. Detect byte order mark if any - otherwise assume default byte buffer.
There are many examples here. The 8 means it uses 8-bit blocks to represent a character. For example the byte sequence 303275 c3 bd in hexadecimal could be ý in UTF-8 or ý in latin1 or Ă in latin2 or 羸 in BIG-5 and so on.
It isnt always possible to find out for sure what the encoding of a text file is. Charsetiso-8859-1 although the file is. What is file encoding and why is it important.
This check can easily be copied and adapted to detect many other encodings that use BOMs. A file with the first three bytes 0xEF0xBB0xBF is probably a UTF-8 encoded file. Carriage return CR and line feed LF.
If they do have lines with the same length you cannot use StreamReader to read the file you must use FileStream. Test UTF8 with BOM. UTF8Encoding encUtf8Bom new UTF8Encodingtrue true.