Classic ASP (VBScript) replace special character in a string is acting strange

◇◆丶佛笑我妖孽 提交于 2019-12-13 13:29:05

问题


In classic ASP (VBScript), when I replace the string, a strange character appears.

<%
    myString = "My Ttitle &#174;"
    myString = Replace(myString,"&#174;", "®")
    Response.Write(myString)
%>

If I print this out to HTML, the final result is (Which has a strange A in it):

My Ttitle ® 

回答1:


  1. add this at the top of your page <%@ language="vbscript" codepage="65001"%>

  2. open your file in a text editor, (notepad will do) select Save As from the file menu and choose utf-8 rather than ANSI encoding

  3. add in your head section <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> (this isn't actually necessary but it doesn't do any harm)

Further information here

http://www.hanselman.com/blog/InternationalizationAndClassicASP.aspx




回答2:


Change

myString = Replace(myString,"&#174;", "®")

to

myString = Replace(myString,"&#174;", "&reg;")



回答3:


Your website encoding is most likely wrong. Add this before your myString declaration.

response.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">')


来源:https://stackoverflow.com/questions/22259401/classic-asp-vbscript-replace-special-character-in-a-string-is-acting-strange

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