I'm trying to do something that, in my opinion, should be fairly simple, but I spent too much time on it, and I tried several different approaches, which I explored, but to no avail.
Basically, I have a huge list of names that have βspecialβ characters from UTF8 encoding in them.
My ultimate goal is to read each name and then make an HTTP request using that name in the URL as a GET variable.
My first goal was to read one name from a file and put it in the standard one to confirm that I could read and write UTF8 correctly before creating lines and doing all HTTP requests.
The test1.txt
file I made contains only this content:
Ownage
Then I used this C # code to read in the file. I set the encoding to StreamReader
and Console.OutputEncoding
to UTF8
.
static void Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.UTF8; using (StreamReader reader = new StreamReader("test1.txt",System.Text.Encoding.UTF8)) { string line; while ((line = reader.ReadLine()) != null) { Console.WriteLine(line); } } Console.ReadLine(); }
To my surprise, I get this conclusion:

The expected result matches the original contents of the file.
How can I be sure that the lines that I am going to create to create HTTP requests will be correct if I cannot even perform a simple task like UTF8 read / write lines?
source share