How can I get CSV file encoding UTF-8 in C#.Net?

后端 未结 3 1617
Happy的楠姐
Happy的楠姐 2021-02-12 19:51

I wanna make CSV file encoding UTF-8. Now, my CSV file cannot show Japanese Fonts. I want C# code to solve this problem.

3条回答
  •  有刺的猬
    2021-02-12 20:51

    SuSanda,
    I'm not sure about your current code or your actual text you're trying to save, but this might get you in the right direction.

    using(var sw = new StreamWriter("testfile_utf8.csv", false, Encoding.UTF8))
    {
        sw.WriteLine("頼もう");
    }
    

    If you open that file in Excel, it will show the Japanese text as expected.
    If you do not include the Encoding.UTF8 parameter, it will display gibberish.

    I hope that's what you're looking for.

提交回复
热议问题