Unicode Hello World Page

走远了吗. 提交于 2019-12-06 16:25:43

问题


Can someone show me a simple ASP script that produces a unicoded webpage? Maybe you could write Hello world in a variety of languages.

Also how can I convert floats to string so that I can produce "2.3" or "2,3" depending on the country the page is being directed to. Does ASP offer functionality for doing this?

Furthermore, how do you convert "A B" to "A B" etc.

Thanks,

Barry


回答1:


Unicode:

There are two parts in creating a true Unicode (utf-8) page. First you will need to output the data as utf-8. To instruct the web server to use utf-8, put this line at the top of your asp-file.

 <%
response.codepage = 65001
response.charset = "utf-8" '//This information is intended for the browser.
%>

Secondly, you'll need to tell the browser which encoding you are using. Put this information the html head tag.

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>

Remember that hard-coded text (in an ASP-file) will be outputted "as is", therefore save the file as utf-8 on disk.

Localization:

Also how can I convert floats to string so that I can produce "2.3" or "2,3" depending on the country the page is being directed to. Does ASP offer functionality for doing this?

Use LCID to change how dates, numbers, currency etc is formatted. Read more here!

<%
Session.LCID = 1053 'Swedish dateformat (and number format)
%>

HTML encoding:

Furthermore, how do you convert "A B" to "A B" etc.

This is very easy. Just use Server.HTMLEncode(string)

<%
Server.HTMLEncode("A B")   '//Will output A&nbsp;B
%>

Example page:

<%
'//This page is encoded as utf-8
response.codepage = 65001  
response.charset = "utf-8"

'//We use the swedish locale so that dates and numbers display nicely
Session.LCID = 1053   '//Swedish 

%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
       <%
           Server.HTMLEncode("Hello world!")     '//English
           Server.HTMLEncode("Hej världen!")     '//Swedish
           Server.HTMLEncode("Γεια σου κόσμε!")  '//Greek
           Server.HTMLEncode("!سلام دنیا")        '//Persian
        %>
    </body>
</html>


来源:https://stackoverflow.com/questions/9735677/unicode-hello-world-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!