C #: Is there a way to find out what encodes a file's encoding?

Is there any way to find out what is encoding the file encoding?

+3
source share
7 answers

The only way to reliably do this is to find the byte order bytes at the beginning of the text file. (This blob is generally a character encoding encoding, as well as encoding, for example, UTF8, UTF16, UTF32). Unfortunately, this method only works for Unicode-based encodings, and nothing before that (for which you need to use much less reliable methods).

The type StreamReadersupports the detection of these labels to determine the encoding - you just need to pass the flag to the parameter as such:

new System.IO.StreamReader("path", true)

stremReader.CurrentEncoding, , . , , - , CurrentEncoding Encoding.Default.

+4

: .NET

Msdn:

ANSI, . StreamReader. , XML HTML, , -, , XmlTextReader, . .

+3

100% - . , . ( ): PowerShell script,

0

, ++, . ( , ):

  • , UTF-32 BE/LE
  • , UTF-16 BE/LE
  • , UTF-8
  • ,

, , , ANSI.

. . , "" "", .

- ( , ).

, , , , .

(, , ASCII, , , .

Win32 IsTextUnicode, , , UTF-16 , , "", " .

0

peterchen, "bush hide the Facts" Notepad.exe, , , .

http://en.wikipedia.org/wiki/Bush_hid_the_facts

0

, , Unicode ( ) ( Windows-1252 "ASCII" .Net .ascii):

http://www.architectshack.com/TextFileEncodingDetector.ashx

, StreamReader, , @peterchen , #:

  • , ,
  • , Unicode COULD.
  • , LIKELY ( , , ).
  • If the “possible” Unicode encodings do not look good, use the default encoding / encoding

Sorry this answer is so late - I just recently cleared the class and posted it on the Internet.

0
source

Source: https://habr.com/ru/post/1716314/


All Articles