28987

Encoding difficulties: £ displaying instead of £

Question:

I am accessing data from an SQL Server database to my ASP.Net C# based website. This data is received from affiliate companies and contains £ for the £ sign. But when I display this data inside a label, instead of £ it shows £.

Note: The & is converted to &.

I know it's a character encoding problem and I've tried to provide the character encoding as 'utf-8' and also 'ISO-8859-1' in the header.

Which character encoding should I use to solve the problem?

Answer1:

It's not a problem with finding the correct character encoding to turn the bytes into text, it's how the text has been encoded (or rather escaped).

The problem is that the text has been HTML encoded twice. The first time it turns the £ into £, the second time into £.

So, to correct this you have to use the HtmlDecode method to reverse the second step.

Answer2:

&amp;#163 <strong>should</strong> render as &#163. By using the &amp; you've escaped the HTML escape code.

Answer3:

It appears to be encoded twice and decoded only once. What was the step it goes through ?

Recommend

  • AngularJS - ngBind and Bootstrap Switch
  • python struct.pack(): pack multiple datas in a list or a tuple
  • Play Framework nested form errors missing
  • Is a .txt file created in VB different than one I'd randomly create?
  • Download/Save/Write a file on the client's hard disk using flash/flex
  • CSS: How to fix overlapping divs
  • Salesforce Different WSDL files and when to use
  • Default parameter as generic type
  • xcode don't localize specific strings
  • Silverlight DependencyProperty.SetCurrentValue Equivalent
  • Zurb Foundation _global.scss meta styles for js?
  • Ajax calls do not work in IE unless you fiddle with security settings
  • Swift: Switch statement fallthrough behavior
  • QLineEdit password safety
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • Encrypt data by using a public key in c# and decrypt data by using a private key in php
  • Controls, properties, events and timers running in design time
  • SSO with signing and signature validation doesn't work
  • Validaiting emails with Net.Mail MailAddress
  • Join two tables and save into third-sql
  • Deserializing XML into class C#
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • How to model a transition system with SPIN
  • Updated Ionic CLI but shows previous version (Windows)
  • Javascript + PHP Encryption with pidCrypt
  • ActionScript 2 vs ActionScript 3 performance
  • How to make Safari send if-modified-since header?
  • To display the title for the current loaction in map in iphone
  • ORA-29908: missing primary invocation for ancillary operator
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Circular dependency while pushing http interceptor
  • Traverse Array and Display in markup
  • Linker errors when using intrinsic function via function pointer
  • How to set the response of a form post action to a iframe source?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • costura.fody for a dll that references another dll
  • Converting MP3 duration time