开发者

Pound signs (£) disappearing from ASP.NET strings

开发者 https://www.devze.com 2023-01-08 23:46 出处:网络
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:

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 S开发者_StackOverflowQL 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.


Use the ASCII code &pound;

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


Use the following:

<% Response.Write("&pound;") %> 


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.


How about this?

<% poundsign = Chr(163) %>
<% Response.Write poundsign %>
<% Response.Write "£" %>
0

精彩评论

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