I have been stumped with this problem of converting a string (which I am assuming is in UTF-16/Unicode) in C# to output to file using ISO-8859-1 encoding.
string s = "Gibt es ein Restaurant in der Nähe"; Encoding iso = Encoding.GetEncoding("ISO-8859-1"); Encoding unicode = Encoding.Unicode; byte[] unicodeBytes = Encoding.Unicode.GetBytes(s); byte[] isoBytes = Encoding.Convert(unicode, iso, unicodeBytes); // convert the new byte[] to char[] char[] isoChars = new char[iso.GetCharCount(isoBytes, 0, isoBytes.Length)]; iso.GetChars(isoBytes, 0, isoBytes.Length, isoChars, 0); StreamWriter sw = new StreamWriter(output, iso); sw.Write(isoChars, 0, isoChars.Length); sw.Write(Environment.NewLine, 0, Environment.NewLine.Length); ' My output text file shows the text with question mark:
Gibt es ein Restaurant in der N?he