0
Follows code:
string text = File.ReadAllText($@"{pathname}", Encoding.UTF8);
I have several txt files with different condition. Because here shows no special characters, because different encoding.
Before running the line File.ReadAllText
, how do I get the file type?
Example: ANSI, UNICODE, UTF-8, ETC...
Something like that:
if (pathname == Encoding.ASCII)
{
string text = File.ReadAllText($@"{pathname}", Encoding.ASCII);
}
else if (pathname == Encoding.UTF8)
{
string text = File.ReadAllText($@"{pathname}", Encoding.UTF8);
}
Is there any way to know if the detected goes wrong ? Vixi screwed me, I will try with library that you indicated me.
– Matheus Miranda
Not reliably, including because the text may be in a poorly formed encoding. Reliable will only be if you can ensure that the file is never corrupted and have a header in the file that indicates the encoding. Eventually this is what you will get in some standard encodings. If you know that you will only have two or three different encodings and which ones help a little because you can limit the choices. It has encodings that can be ambiguous.
– Maniero
I understand you can tell me which is the safest way to know which type of encoding?
– Matheus Miranda
One of those right there, but I don’t know which one. Then you can manually refine to make less error. But test because it might go well with the pattern you have.
– Maniero
I understand, the best library (in my opinion) is UDE. Because it speaks the type of encoding and the level of file TRUST that returns
float
. That’s what you wrote in the commentary:o texto pode estar em uma codificação mal formada
.– Matheus Miranda
Bora delete comment ?
– Matheus Miranda