0

I have a process that essentially works like this:

  1. MyText is inserted into textbox in MainForm.asp
  2. MainForm.asp OnSubmit redirects to Submit.asp
  3. In Submit.asp:
<% myText = Upload.Form("MyText") %>
myText = #<%=myText%>
<% myText = FixQuotes(myText) %>
  1. myText is inserted into a sql database
  2. View.asp calls myText from the database
  3. View.asp prints myText

I'm running into a problem where smart quotes (curly quotes, where there's a difference between a beginning quote and end quotes) are printing as gibberish characters like “ by the time we get to step 6.

I believe that the smart quotes still exist as themselves and not the gibberish by the time we get to step 3, and so I am attempting to use the following function to fix the quotes to straight quotes. I'm not sure exactly what my parameters for the Replace() should be, so an extra set of eyes would be helpful. What I currently have doesn't actually work.

Function FixQuotes (tempString)
        tempString = Replace(tempString, ChrW(&H201c), "&quote") 'double left quote
        tempString = Replace(tempString, ChrW(&H201d), """") 'double right quote
        FixQuotes = tempString
end function

However, it is quite possible that the quotes turn to the gibberish as soon as MainForm submits. In which case, I'm not really sure how I should handle the replacement.

For reference, I have <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> in the heads of all my pages.

Edit: Additional information

  • The other option would be to have a JavaScript function that does the replace before the submit. I've used that in the past. – Dijkgraaf Jul 23 '20 at 23:18
  • 4
    Another option would be to configure the text encoding properly so you don’t have such issues – Stephen R Jul 24 '20 at 02:36
  • 2
    As @StephenR has pointed out you will have an encoding mismatch and the way to deal with that is not trying to `Replace()` the characters it's to correctly encode the content before it reaches the browser. – user692942 Jul 24 '20 at 08:13
  • 1
    This is worth a read - `Response.CodePage = 65001` is probably the most useful suggestion. https://www.hanselman.com/blog/InternationalizationAndClassicASP.aspx – John Jul 24 '20 at 17:44

0 Answers0