chris
chris

Reputation: 3911

HTML Entity in CSVs

How do I add an html entity to my CSV?

I have an asp.net, sql server that generates html, excel, and csv files. Some of the data needs to have the ‡ entity in it. How do I get it to output to my CSV correctly? If I have it like this: ‡, then it gets screwed up but if I output it with the entity code, the CSV outputs that text.

Upvotes: 1

Views: 556

Answers (2)

ChrisLively
ChrisLively

Reputation: 88072

I'm not sure what you mean by "it gets screwed up".

Regardless, it is up to the receiving program or application to properly interpret the characters.

What this means is that if you put ‡ in your csv file then the application that opens the CSV will have to look for those entities and understand what to do with them. For example, the opening application would have to run an html entity decoder in order to properly display it.

If you are looking at the CSV file with notepad (for example) then of course it won't decode the entities because notepad has no clue what html entities are or even what to do when it finds them.

Even Internet Explorer wouldn't convert the entities for display when opening a CSV file. Now if you gave it a .html extension then IE would handle the display of the file with it's html rendering engine.

Upvotes: 0

Blindy
Blindy

Reputation: 67437

Non-printable characters in a field are sometimes escaped using one of several c style character escape sequences, ### and \o### Octal, \x## Hex, \d### Decimal, and \u#### Unicode.

So just escape your non-ascii character C#-style and you'll be fine.

Upvotes: 3

Related Questions