如何在C#.Net中获取编码UTF-8的CSV文件? [英] How can I get CSV file encoding UTF-8 in C#.Net?

查看:318
本文介绍了如何在C#.Net中获取编码UTF-8的CSV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作编码UTF-8的CSV文件.现在,我的CSV文件无法显示日语字体.我想要C#代码来解决此问题.

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

推荐答案

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.

这篇关于如何在C#.Net中获取编码UTF-8的CSV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆