string 经典 ASP (VBScript) 替换字符串中的特殊字符表现很奇怪
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22259401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Classic ASP (VBScript) replace special character in a string is acting strange
提问by user1187968
In classic ASP (VBScript), when I replace the string, a strange character appears.
在经典的 ASP (VBScript) 中,当我替换字符串时,会出现一个奇怪的字符。
<%
myString = "My Ttitle ®"
myString = Replace(myString,"®", "?")
Response.Write(myString)
%>
If I print this out to HTML, the final result is (Which has a strange A in it):
如果我将其打印为 HTML,则最终结果是(其中有一个奇怪的 A):
My Ttitle ??
回答by John
add this at the top of your page
<%@ language="vbscript" codepage="65001"%>
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
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)
将此添加到页面顶部
<%@ language="vbscript" codepage="65001"%>
在文本编辑器中打开文件,(记事本可以)从文件菜单中选择另存为,然后选择 utf-8 而不是 ANSI 编码
添加在您的头部部分
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
(这实际上不是必需的,但它不会造成任何伤害)
Further information here
更多信息在这里
http://www.hanselman.com/blog/InternationalizationAndClassicASP.aspx
http://www.hanselman.com/blog/InternationalizationAndClassicASP.aspx
回答by meda
Change
改变
myString = Replace(myString,"®", "?")
to
到
myString = Replace(myString,"®", "®")
回答by Rich
Your website encoding is most likely wrong. Add this before your myString declaration.
您的网站编码很可能是错误的。在 myString 声明之前添加它。
response.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">')