4

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 ® 
Rich
  • 4,134
  • 3
  • 26
  • 45
user1187968
  • 7,154
  • 16
  • 81
  • 152

3 Answers3

6
  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

John
  • 4,658
  • 2
  • 14
  • 23
1

Change

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

to

myString = Replace(myString,"&#174;", "&reg;")
meda
  • 45,103
  • 14
  • 92
  • 122
  • 1
    `®` gives the ® symbol anyway. so this is just swapping one HTML representation for another. I'd guess he wants the ® to appear in source code or he wouldn't be doing this – John Mar 08 '14 at 11:25
  • Do not do this please! Use @John suggestion as it fixes the route cause of the problem. – user692942 Mar 10 '14 at 09:55
0

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">')
Rich
  • 4,134
  • 3
  • 26
  • 45
  • Don't do this either, specifying the encoding correctly from the server side is the way to go, relying on meta tag in html causes issues down the line, better to let the server return the correct response rather then relying on the browser. – user692942 Mar 10 '14 at 18:57
  • The solution that worked did rely on the browser. Rather than cutting down others answers, why don't you suggest how to fix the server? – Rich Mar 10 '14 at 19:07
  • Actually it's point 1 and 2 that are the solution. Plus I don't see the point in answering when someone already has, only answer if something has been missed. – user692942 Mar 10 '14 at 19:12
  • Plus I've have before but people just don't [search](http://stackoverflow.com/a/21914278/692942) – user692942 Mar 10 '14 at 19:47