CSV文件中的Unicode? [英] Unicode in CSV file?

查看:706
本文介绍了CSV文件中的Unicode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要生成一个CSV文件.也许我做错了",因为我总是用自己的代码转储文件,而不是使用lib.

I need to generate a CSV file. Maybe i am 'doing it wrong' because i am dumping the file with my own code instead of using a lib but anyways.

看来我没事了.引号,逗号和所有内容似乎都已完美逃脱.这很容易.问题是我正在使用unicode字符串进行测试,它们以????的形式出现.当我使用MS Excel保存带有测试字符串的文件时,我按另存为CSV格式打开文件时,遇到了同样的问题(unicode字母变成?????).不支持unicode吗?

It looks like i have everything right. Quotes, commas and everything seems to be escaped perfectly. It was rather easy. The problem is i am using unicode strings to test and they come out as ????. When i use MS Excel to save a file with my test string and i hit save as CSV opening the file gets me the same problem (unicode letters becoming ?????). Is unicode not supported?

我只是尝试像这样转储字符串,而不是将其输出到网页

I just tried dumping the string like this instead of outputting it to a webpage

var f = new System.IO.StreamWriter(filename, false, System.Text.Encoding.Unicode);

现在我看到unicode文本,但是现在所有内容都在一栏中.奇怪的是,在我选择的文本编辑器中,一切看起来都很正常,如果我复制/粘贴了几列,然后将其粘贴为.csv并保存,我会看到这些列很好.尽管它可能会去除unicode.

and now i see the unicode text but everything is now in one column. Whats weird is everything looks normal in my text editor of choice and if i copy/paste a few columns out and paste it in saving as .csv i see the columns fine. Although it probably strips unicode out.

我如何正确保存此内容?

How do i save this properly?

推荐答案

System.Text.Encoding.Unicode使用UTF-16编码.尝试告诉您的文本编辑者使用UTF-16进行解码;我猜您用来显示输出文件的编辑器默认为UTF-8或ASCII.如果是这样,则替代方法可能是使用System.Text.Encoding.UTF8编码输出.

System.Text.Encoding.Unicode uses UTF-16 encoding. Try telling your text-editors to decode with UTF-16; I'm guessing the editor you are using to display the output file is defaulting to UTF-8 or ASCII. If this is so, an alternative might be to encode the output with System.Text.Encoding.UTF8 instead.

这篇关于CSV文件中的Unicode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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