I have an UTF8 file, which I have added to my project in Resources.resx, called Template.txt
If I read the file normally like this:
string template = File.ReadAllText(@"filepath\Template.txt", Encoding.UTF8);
Everything works fine.
However if I read it like this:
string template = Properties.Resources.Template
It is filled with Japanese characters, and thus has the wrong encoding.
byte[] bytes = Encoding.Default.GetBytes(Properties.Resources.Template);
string template = Encoding.UTF8.GetString(bytes);
This also still gives Japanese characters.
Does anyone know the cause? If I just double click the Template.txt file in Visual Studio, I can just read it normally also.
As Hans Passant said in the comments, encoding the file so that it includes the UTF-8 BOM (Byte Order Mark) fixed the issue.
In VS, select the Resources.resx
file, then go File > Save Resources.resx As...
and Save with Encoding...
and select Unicode(UTF-8 without signature) - Codepage 65001
and OK
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With