且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#.Net中获取编码UTF-8的CSV文件?

更新时间:2023-11-27 10:16:10

SuSanda,
我不确定您要保存的当前代码或实际文本,但这可能会为您提供正确的方向.

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("頼もう");
}

如果在Excel中打开该文件,它将按预期显示日语文本.
如果不包括Encoding.UTF8参数,它将显示乱码.

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.