views:

90

answers:

4

Hi all,

I'm usually a LAMP developer, but some .NET work has arrived on my plate and I'm a bit stumped.

If I run the following code:

<% poundsign = "£" %>
<% Response.Write poundsign %>
<% Response.Write "£" %>

… nothing is displayed. However, outside of the <% %> tags (ie in the HTML) £ displays correctly.

I have no trouble displaying the usual alphanumerics, it's just the £ sign that is proving problematic. The underlying file is in Windows 1252 encoding, and I need to serve it as such. If I save the file as UTF-8, I get mojibake instead of a £.

Does anybody have any idea what I can do to make this work, or any settings that might be preventing it from working (other than saving the file in a different format)? Thanks in advance.

EDIT: Sorry guys, I should have mentioned earlier, but &pound; won't help. Aside from the fact that my £s aren't appearing on the page, a major part of my problem is that I need to insert strings containing £ into a SQL server database, but if I form a SQL INSERT statement within the ASP, none of the £ signs end up appearing in the database. Inserting £ signs into the database from ASP isn't a problem when I save the .asp files as UTF-8 files, but I need everything to work in Windows 1252 encoding. Thanks again.

+4  A: 

Use the ASCII code &pound;

It is an HTML entity and needs to be accessed via the code, read more here.

Dustin Laine
Thanks for your answer – alas HTML entities won't help me out, for reasons now explained in my original post. Sorry for not being clearer in the first place!
Sebastian Motraghi
Not sure, £ is part of the Windows 1252 encoding character set, see http://en.wikipedia.org/wiki/Windows-1252
Dustin Laine
+3  A: 

Use the following:

<% Response.Write("&pound;") %> 
Blue Steel
A: 

How about this?

<% poundsign = Chr(163) %>
<% Response.Write poundsign %>
<% Response.Write "£" %>
Aaron D
Oddly enough, chr(163) is displaying as "s".
Sebastian Motraghi
+2  A: 

Thanks for your help, everybody. It turns out that the problem was caused by my Windows-1252 ASP file loading a UTF-8 include, thereby messing up the encoding of the resultant page.

Sebastian Motraghi