Replacing Apostrophes in Classic ASP

I have a function that replaces apostrophes with ~ or ~~ for my datbase insertion; however, whenever something is pasted into the textbox from office, the apostrophe takes on a different character.

' is what I have programmed for; however, ’ is what is created via office (straight vs curly).

I tried the following code but it does not recognize the curly apostrophes:

Function ReplaceQuotesSave(strData)
      strData = Replace(strData, "'", "~")
      strData = Replace(strData, "’", "~")
      strData = Replace(strData, """", "~~")
      strData = Replace(strData, "“", "~~")      

      ReplaceQuotesSave = Trim(strData)
End Function

It works great on the straight apostrophe (').

Anyone know how to deal with the curly apostrophes in asp?
dzirkelbAsked:
Who is Participating?
 
imnictConnect With a Mentor Commented:
You have something more going on here.  Testing your example here gives renders quite different:

I used this:
response.write(Server.HTMLEncode("There’s")&"<br><Br>")
response.write("There’s<br><br>")

To get this in the browser:
There’s

There’s

Which is rendered in html as:
There&#8217;s<br><Br>There’s<br><br>

What character set is being used on the server and client browser?

Also, when I changed to using URLEncode, I got results that may work for you:
response.write(Server.urlEncode("There’s")&"<br><Br>")

produces:
There%92s

So -

strData = Replace(Server.URLEncode(strData), "%27", "~")
strData = Replace(Server.URLEncode(strData), "%60", "~")
strData = Replace(Server.URLEncode(strData), "%92", "~")
strData = Replace(Server.URLEncode(strData), "%93", "~")
strData = Replace(Server.URLEncode(strData), "%B4", "~")

You will want these checks to be after the remaining character checks that you can successfully catch without encoding the form input.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>I have a function that replaces apostrophes with ~ or ~~ for my datbase insertion
you don't need that if you do the insert properly
example with stored procedure: http://www.freevbcode.com/ShowCode.Asp?ID=3687
example with plain insert: http://social.msdn.microsoft.com/Forums/en-US/sqldataaccess/thread/d1e9ec4c-7fbd-4b04-ba37-4758f0300fec

once you use the parameters instead of building the insert sql ad-hoc, you don't need to replace any character at all for the sql ...
0
 
dzirkelbAuthor Commented:
I am not interested in that route at this time, I would just like my specific issue resolved.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
niralshahCommented:
try this

strData = Replace(strData, CHR(39), "~")
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
well...
Function ReplaceQuotesSave(strData)
      strData = Replace(strData, "'", "~")
      strData = Replace(strData, "’", "~")
      strData = Replace(strData, "`", "~")
      strData = Replace(strData, "‘", "~")
      strData = Replace(strData, "’", "~")
      strData = Replace(strData, """", "~~")
      strData = Replace(strData, "“", "~~")      
      strData = Replace(strData, "”", "~~")      

      ReplaceQuotesSave = Trim(strData)
End Function

Open in new window

0
 
dzirkelbAuthor Commented:
Ok, I did a little more troubleshooting, and here is what I found.

I am just printing to the screen a request.form of the data, and that is dropping the curly apostrophe, without any code involved.

As an example:

test’s was placed into a textbox and posted to another page.  The other page prints this to the screen:

tests

The first line of code on the page is response.write(requst.form("txtData"))

So, any ideas on what would cause this?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
for the output, see the HTMLencode method:
http://www.w3schools.com/ASP/met_htmlencode.asp
0
 
dzirkelbAuthor Commented:
response.write(Server.HTMLEncode("There’s")) outputs There’s

response.write(Server.HTMLEncode(request.form("txtData"))) outputs Theres

I am definately confused.
0
 
imnictCommented:
to add, you will want to look for the other ASCII variants that may be causing you grief.

strData = Replace(strData, CHR(145), "~")
strData = Replace(strData, CHR(146), "~")
0
 
dzirkelbAuthor Commented:
I think this is happening before I can even do a replace function, as displaying a request.form to the page strips the curly apostrophe, so the replace function won't even find the curly apostrophe in the first place.
0
 
dzirkelbAuthor Commented:
response.write(Server.HTMLEncode("There**curlyapostrophe**s")) outputs There**curlyapostrophe**s
response.write("There**curlyapostrophe**s") outputs There’s
response.write(Server.HTMLEncode(request.form("txtData"))) outputs Theres
response.write(request.form("txtData")) outputs Theres

where **curlyapostrophe** is equal to a curly apostrophe

0
 
imnictCommented:
Try these:

strData = Replace(Server.HTMLEncode(strData), "%27", "~")
strData = Replace(Server.HTMLEncode(strData), "%60", "~")
strData = Replace(Server.HTMLEncode(strData), "%92", "~")
strData = Replace(Server.HTMLEncode(strData), "%93", "~")
strData = Replace(Server.HTMLEncode(strData), "%B4", "~")

Unicode character reference: Unicode Character Reference
0
 
dzirkelbAuthor Commented:
It still just strips the curly apostrophe and does not display anything.

Could the reason behind this be due to some font not being installed on the server and it is not recognizing it at all?
0
 
imnictCommented:
It's not likely to be a font on the server.  More likely is to determine what character is really in the string.

Quote:
response.write("There**curlyapostrophe**s") outputs There’s

If you view the source html rendered, what is actually being sent to the browser?
0
 
dzirkelbAuthor Commented:
There&#8217;s<br><Br>There’s<br><br>Theres

Is outputed by going to view source

response.write(Server.HTMLEncode("There’s")&"<br><Br>")
response.write("There’s<br><br>")
response.write(Server.HTMLEncode(request.form("txtData")))

is the code producing that text
0
 
dzirkelbAuthor Commented:
How do I find the character set being used on the server and client browser?  I think that is the problem.
0
 
imnictCommented:
Which platform are you running?  IISx, or some mod_whatever on apache?
0
 
dzirkelbAuthor Commented:
iis6.0 on a server 2003 box
0
 
imnictCommented:
Check in the control panel, Regional and Language Options.

Check in Internet Explorer on the server under tools | options, General Tab, Languages to see what is installed there as well.

Also check the top of your asp page.  Frontpage, Web Developer Express, Visual Studio, Dreamweaver...  like to add a language line at the top of the page.  It would look something like:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

0
 
dzirkelbAuthor Commented:
IE language is English (United States) [en-us]

regional langauge keyboard settings are set to US, and the Turn Off advanced text services is checked.

For adding the code, I get this error:

Active Server Pages error 'ASP 0245'

Mixed usage of Code Page values

/EzineTech-edit-individual-save.asp, line 1

The @CODEPAGE value specified differs from that of the including file's CODEPAGE or the file's saved format.
0
 
imnictCommented:
Ok - so you have an included file that has this line already defined or it already existed in your file elsewhere down the line list.  Once you find it, from the error it differs from the default.  What is it set to?
0
 
dzirkelbAuthor Commented:
This is all I have on the coded page:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
response.write("hello world")
%>

and I still get the error.
0
 
imnictCommented:
Do you have any additional headers defined for the iis site?
0
 
dzirkelbAuthor Commented:
I do have a web.config file for some .net pages.

And, I am seeing in the custom http headers section that there is one for X-Powerd-By: ASP.Net
0
 
imnictCommented:
Remove the codepage line from your test asp page and insert this:

<%
Response.Write(Session.CodePage)
%>

What does it return?
0
 
imnictConnect With a Mentor Commented:
Also, in your web.config for asp.net, what is in the following keys?

<globalization
            requestEncoding="utf-8"
            responseEncoding="utf-8"  />
0
 
dzirkelbAuthor Commented:
<%
Response.Write(Session.CodePage)
%>

returns 1252

for the web.config file, there is no flobalization tag, it was not created in visual studio, so it is a stripped down config file.
0
 
Kumaraswamy RCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0
All Courses

From novice to tech pro — start learning today.