Have the following codeblock that saves a file with the selected encoding. When the file is opened in a text editor it shows the encoding as ASCII..
StringBuilder sb = new StringBuilder();
sb.Append(); // Lots of korean text here
Encoding enc = Encoding.GetEncoding(51949);
using (StreamWriter sw = new StreamWriter(fileName, false, enc))
{
sw.Write(sb.ToString());
sw.Flush();
sw.Close();
}
Can anyone help?
Thanks
You have to use UnicodeEncoding while saving the file, and for unicode Encoding, this the below code, and modify as per your need. try this:
You should use
Encoding.Unicode
- so the output will include the BOM and will be encoded in Unicode multi-byte.There is nothing in the file that tells the text editor the encoding.
You need to sup0ply metadata in some way. Either by getting the user to use some "open with selected encoding" option in the text editor (if it has one), or use a different encoding in the file (eg. UTF-8 or -16 with a BOM) that includes the code points you need, and the text editor can detect.
Try replacing
Encoding enc = Encoding.GetEncoding(51949);
with
Encoding enc = Encoding.Unicode;
or
Encoding enc = Encoding.UTF8;