Reputation: 359
My code is:
var previousLines = new HashSet<string>();
File.WriteAllLines("D:\\textfile2.txt",
File.ReadLines("textfile1.txt").Where(line => previousLines.Add(line)),
Encoding.GetEncoding("ISO-8859-2"));
I have two text files. In textfile1.txt
I have words with letters like ł,ą,ę etc.
I want to rewrite all lines with no duplicates to the file textfile2.txt
, but the encoding doesn't work as I expected. It eats some letters such as ł,ą,ę. Why is this happening?
Upvotes: 1
Views: 5519
Reputation: 13662
You need to use the same encoding you used to write textfile1.txt
. By default, UTF-8 is used for reading in File.ReadLines
.
If you've used ISO-8859-2 when you wrote it, you'll need to specify it:
File.ReadLines("textfile1.txt", Encoding.GetEncoding("ISO-8859-2"))
Upvotes: 2