开发者

Output Unicode to CSVs from ASP.NET

I am trying to output an entity (¹) or its unicode equilvalent (UTF-16 (decimal) 185) to a CSV file.

I generate a string that then outputs to a csv 开发者_StackOverflow中文版in .Net. Is there an easy way to do this?


The easiest way would be just to write the string containing that character to the file. That assumes, of course, that you're writing the file in one of the Unicode encodings like Encoding.UTF8 or Encoding.Unicode, or in an encoding that includes that character.

The real question is what you want to do with that CSV file later. If you're going to read it from an application that understands UTF8, then I'd argue that the best way would be create the file with UTF8 encoding and then just write the character. I'm pretty sure that Excel understands UTF8. So you should be able to write your CSV with:

using (var writer = new StreamWriter(filename, false, Encoding.UTF8))
{
    // write CSV here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜