cdub
cdub

Reputation: 25731

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 in .Net. Is there an easy way to do this?

Upvotes: 1

Views: 1041

Answers (1)

Jim Mischel
Jim Mischel

Reputation: 134085

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
}

Upvotes: 1

Related Questions