printing character ' and " in asp using vbscript

S

S N

how to print apostrophe character ' and double quote " in asp using
vbscript.
my code using response.write replaces " character with inverted question
mark.
please help
 
S

S N

how to print apostrophe character ' and double quote " in asp using
vbscript. my code using response.write replaces " character with question
mark.
please help
 
B

Bob Barrows [MVP]

Jon said:
'******************************************************************
Function DataPrep(strText)
'
'PURPOSE: prep data text entry
'
'PARAMETERS: strText -- text string to modify
'******************************************************************
If NOT isNull(strText) then

DataPrep = Replace(strText, ";", "")
DataPrep = Replace(DataPrep, "'", "'")
DataPrep = Replace(DataPrep, """", """)
DataPrep = Replace(DataPrep, "<", "&lt;")
DataPrep = Replace(DataPrep, ">", "&gt;")

End if

End Function
??
What's wrong with

Response.Write Server.HTMLEncode(strText)
 
E

Evertjan.

Jon Paal [MSMD] wrote on 17 mrt 2008 in
microsoft.public.inetserver.asp.general:
"Dataprep" type function allows for customization, otherwise nothing
wrong with your suggested solution...

whose?
 
M

msnews

where to get the values of constants like &apos and &quot
also i want to replace single " and not double ""

please advise
 
D

Daniel Crichton

&apos; and &quot; are HTML entities - these are converted by web browsers
into ' and " respectively.

If you just want to print the literal characters, that's easy enough:

Response.Write """"

will print a single " (there are 4 " in that line, the two outer ones are
the string containers, the two inners generate the single " as doubling them
up inside a string turns them into a literal instead).

another example

Response.Write "<a href=""http://myurl.com/apage.asp"">This is a link</a>"

Notice how you just double up the quotation marks.

For an apostrophe you don't need to do anything special:

Response.Write "They're not here"

So what problem are you having with quotes and apostrophes?


Dan

msnews wrote on Mon, 17 Mar 2008 15:05:23 +0530:
where to get the values of constants like &apos and &quot also i want
to replace single " and not double ""
please advise
 
B

Bob Barrows [MVP]

Daniel said:
&apos; and &quot; are HTML entities - these are converted by web
browsers into ' and " respectively.

If you just want to print the literal characters, that's easy enough:

Response.Write """"

will print a single " (there are 4 " in that line, the two outer ones
are the string containers, the two inners generate the single " as
doubling them up inside a string turns them into a literal instead).

another example

Response.Write "<a href=""http://myurl.com/apage.asp"">This is a
link</a>"
Notice how you just double up the quotation marks.

For an apostrophe you don't need to do anything special:

Response.Write "They're not here"

So what problem are you having with quotes and apostrophes?

From the original post: "my code using response.write replaces " character
with question
mark"

It's most likely a codepage problem. I've been holding back from replying to
this because Anthony typically has the most reliable advice for these
situations.
 
D

Daniel Crichton

Bob wrote on Mon, 17 Mar 2008 06:43:16 -0400:
From the original post: "my code using response.write replaces "
character with question mark"

I missed that, I'd been reading the other replies.
It's most likely a codepage problem. I've been holding back from
replying to this because Anthony typically has the most reliable
advice for these situations.

Then again it could be anything without the OP supplying example code that
has the problem, as it might be down to the way he's trying to print those
characters (for instance, using CHR(X) and providing the wrong X value).
 
A

Anthony Jones

Bob Barrows said:
From the original post: "my code using response.write replaces " character
with question
mark"

It's most likely a codepage problem. I've been holding back from replying to
this because Anthony typically has the most reliable advice for these
situations.

Thanks for the vote of confidence Bob but it baffles me. ;)

Since " is within the lower ascii range 0-127 the only encoding that could
screw this up would be UTF-16. But if the browser thought it was getting
say Windows-1252 and yet the server was encoding to UTF-16 (or vice versa)
the content would be completely garbled.

I suspect that what the OP thinks is happening and what actually is are very
different. Like Dan says I think we would need to see some actual code to
make sense of this.
 
S

S N

i am attaching the sample code. actually i am printing from a field in access database. the text entered in the database contains single quotes and double quotes. when i try to print them using response.write, the double quotes are getting replaced with question marks. i have tried the method of

DataPrep = Replace(DataPrep, """", "&quot;")

still problem remains.

i also tried
response.write(server.htmlencode(myrs(3))) ' where myrs is adodb recordset

still the problem remains

i am also attaching the header lines from my asp page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

the problem is still not solved

please help
 
P

Paul Randall

Within VBScript strings, all characters are stored as 16-bit Unicode values, so you can't easily tell whether your string contains Unicode or not. Depending on how well the data was scrubbed before being put in the database, it may contain some Unicode. Depending on how your computer is set up, it is not obvious when you display Unicode characters in a message box. VBScript includes a number of functions for interacting with Unicode characters -- the W versions of things like ChrW and AscW.

Here is a short script that demonstrates a message box displaying a string that includes a Unicode character (that looks something like a single quote) and the same string with that character removed (using a simple regular expression).

Dim s
s = "Hello *" & ChrW(900) & "* unicode"
msgbox s & vbcrlf & sRemoveUnicode(s)

Function sRemoveUnicode(sAnyString)
'Returns sAnyString with all unicode [actually, all
' characters outside the range ChrW(0) to
' ChrW(255)] removed. VBScript strings are made
' up of 16-bit characters so they can handle a
' lot of unicode stuff.

With New RegExp
.Pattern = "[^\u0000-\u007F]"
sRemoveUnicode = .Replace(sAnyString, "")
End With

End Function

-Paul Randall

i am attaching the sample code. actually i am printing from a field in access database. the text entered in the database contains single quotes and double quotes. when i try to print them using response.write, the double quotes are getting replaced with question marks. i have tried the method of

DataPrep = Replace(DataPrep, """", "&quot;")

still problem remains.

i also tried
response.write(server.htmlencode(myrs(3))) ' where myrs is adodb recordset

still the problem remains

i am also attaching the header lines from my asp page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

the problem is still not solved

please help
 
A

Anthony Jones

My guess is that they are not " " but are ' " " typically cut'n'pasted in from Microsoft Word.

These are still in the Windows-1252 range of characters but are not strictly in the iso-8859-1 set.

Don't use http-equiv meta tags use real headers instead.

IOW ditch the meta tags and include this:-

<%Response.CharSet = "Windows-1252"%>

I'm not hopeful because you are probably using IE and IE will treat ISO-8859-1 as Windows-1252 anyway.

Always use Server.HtmlEncode on values retrieved from the Database. Stop mucking about with any other approach.

If that doesn't work view the html source from the browser. What is the server actually sending.

Another alternative is stop using Windows-1252.

Save your pages as UTF-8 change the codepage at the top of the page to 65001 and include Response.CharSet = "UTF-8" in your page.

BTW, Have you looked at the field content directly using the DB management tool?


--
Anthony Jones - MVP ASP/ASP.NET
i am attaching the sample code. actually i am printing from a field in access database. the text entered in the database contains single quotes and double quotes. when i try to print them using response.write, the double quotes are getting replaced with question marks. i have tried the method of

DataPrep = Replace(DataPrep, """", "&quot;")

still problem remains.

i also tried
response.write(server.htmlencode(myrs(3))) ' where myrs is adodb recordset

still the problem remains

i am also attaching the header lines from my asp page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

the problem is still not solved

please help
 
S

S N

you have guessed it right, i am copying the text from ms word but am cleaning wordhtml using wordcleaner 3.
further, i checked using
Response.CharSet = "UTF-8"
in this case the ? characters appears on every newline including the places where it was appearing earlier.

when i use
<%Response.CharSet = "Windows-1252"%>

still the problem of question marks remain. but it appears only as was appearing earlier (in place of " and not on every new line)
i checked the view source- the server is sending ? character itself to the browser.
when i checked the database field, it is showing in invalid character in the shape of a rectangle stored where i want the double quote " printed.

please help.
My guess is that they are not " " but are ' " " typically cut'n'pasted in from Microsoft Word.

These are still in the Windows-1252 range of characters but are not strictly in the iso-8859-1 set.

Don't use http-equiv meta tags use real headers instead.

IOW ditch the meta tags and include this:-

<%Response.CharSet = "Windows-1252"%>

I'm not hopeful because you are probably using IE and IE will treat ISO-8859-1 as Windows-1252 anyway.

Always use Server.HtmlEncode on values retrieved from the Database. Stop mucking about with any other approach.

If that doesn't work view the html source from the browser. What is the server actually sending.

Another alternative is stop using Windows-1252.

Save your pages as UTF-8 change the codepage at the top of the page to 65001 and include Response.CharSet = "UTF-8" in your page.

BTW, Have you looked at the field content directly using the DB management tool?


--
Anthony Jones - MVP ASP/ASP.NET
i am attaching the sample code. actually i am printing from a field in access database. the text entered in the database contains single quotes and double quotes. when i try to print them using response.write, the double quotes are getting replaced with question marks. i have tried the method of

DataPrep = Replace(DataPrep, """", "&quot;")

still problem remains.

i also tried
response.write(server.htmlencode(myrs(3))) ' where myrs is adodb recordset

still the problem remains

i am also attaching the header lines from my asp page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

the problem is still not solved

please help
 
S

S N

i changed the codepage tp 65001 and charset to utf-8, then the question mark ? showing earlier, has changed to the rectangle as shown below.

the database field also shows the same character stored in it.
please help.

My guess is that they are not " " but are ' " " typically cut'n'pasted in from Microsoft Word.

These are still in the Windows-1252 range of characters but are not strictly in the iso-8859-1 set.

Don't use http-equiv meta tags use real headers instead.

IOW ditch the meta tags and include this:-

<%Response.CharSet = "Windows-1252"%>

I'm not hopeful because you are probably using IE and IE will treat ISO-8859-1 as Windows-1252 anyway.

Always use Server.HtmlEncode on values retrieved from the Database. Stop mucking about with any other approach.

If that doesn't work view the html source from the browser. What is the server actually sending.

Another alternative is stop using Windows-1252.

Save your pages as UTF-8 change the codepage at the top of the page to 65001 and include Response.CharSet = "UTF-8" in your page.

BTW, Have you looked at the field content directly using the DB management tool?


--
Anthony Jones - MVP ASP/ASP.NET
i am attaching the sample code. actually i am printing from a field in access database. the text entered in the database contains single quotes and double quotes. when i try to print them using response.write, the double quotes are getting replaced with question marks. i have tried the method of

DataPrep = Replace(DataPrep, """", "&quot;")

still problem remains.

i also tried
response.write(server.htmlencode(myrs(3))) ' where myrs is adodb recordset

still the problem remains

i am also attaching the header lines from my asp page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

the problem is still not solved

please help
 
S

S N

i am sorry, but the character showing as rectangle in my pc during composing of the message to this group, is now showing as ' in the message finally appearing on the server.
please help
i changed the codepage tp 65001 and charset to utf-8, then the question mark ? showing earlier, has changed to the rectangle as shown below.
'
the database field also shows the same character stored in it.
please help.

My guess is that they are not " " but are ' " " typically cut'n'pasted in from Microsoft Word.

These are still in the Windows-1252 range of characters but are not strictly in the iso-8859-1 set.

Don't use http-equiv meta tags use real headers instead.

IOW ditch the meta tags and include this:-

<%Response.CharSet = "Windows-1252"%>

I'm not hopeful because you are probably using IE and IE will treat ISO-8859-1 as Windows-1252 anyway.

Always use Server.HtmlEncode on values retrieved from the Database. Stop mucking about with any other approach.

If that doesn't work view the html source from the browser. What is the server actually sending.

Another alternative is stop using Windows-1252.

Save your pages as UTF-8 change the codepage at the top of the page to 65001 and include Response.CharSet = "UTF-8" in your page.

BTW, Have you looked at the field content directly using the DB management tool?


--
Anthony Jones - MVP ASP/ASP.NET
i am attaching the sample code. actually i am printing from a field in access database. the text entered in the database contains single quotes and double quotes. when i try to print them using response.write, the double quotes are getting replaced with question marks. i have tried the method of

DataPrep = Replace(DataPrep, """", "&quot;")

still problem remains.

i also tried
response.write(server.htmlencode(myrs(3))) ' where myrs is adodb recordset

still the problem remains

i am also attaching the header lines from my asp page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

the problem is still not solved

please help
 
S

S N

i have changed the codepage and charset on all pages of my website to 65001 and utf-8.
but now even apostrophe is showin as a rectangle or strange character.
please help.
i am sorry, but the character showing as rectangle in my pc during composing of the message to this group, is now showing as ' in the message finally appearing on the server.
please help
i changed the codepage tp 65001 and charset to utf-8, then the question mark ? showing earlier, has changed to the rectangle as shown below.
'
the database field also shows the same character stored in it.
please help.

My guess is that they are not " " but are ' " " typically cut'n'pasted in from Microsoft Word.

These are still in the Windows-1252 range of characters but are not strictly in the iso-8859-1 set.

Don't use http-equiv meta tags use real headers instead.

IOW ditch the meta tags and include this:-

<%Response.CharSet = "Windows-1252"%>

I'm not hopeful because you are probably using IE and IE will treat ISO-8859-1 as Windows-1252 anyway.

Always use Server.HtmlEncode on values retrieved from the Database. Stop mucking about with any other approach.

If that doesn't work view the html source from the browser. What is the server actually sending.

Another alternative is stop using Windows-1252.

Save your pages as UTF-8 change the codepage at the top of the page to 65001 and include Response.CharSet = "UTF-8" in your page.

BTW, Have you looked at the field content directly using the DB management tool?


--
Anthony Jones - MVP ASP/ASP.NET
i am attaching the sample code. actually i am printing from a field in access database. the text entered in the database contains single quotes and double quotes. when i try to print them using response.write, the double quotes are getting replaced with question marks. i have tried the method of

DataPrep = Replace(DataPrep, """", "&quot;")

still problem remains.

i also tried
response.write(server.htmlencode(myrs(3))) ' where myrs is adodb recordset

still the problem remains

i am also attaching the header lines from my asp page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

the problem is still not solved

please help
 
A

Anthony Jones

You need to make sure response.charset and response.codepage are consistent otherwise you will get mess.

Its clear that you problem is with the data in the DB.

--
Anthony Jones - MVP ASP/ASP.NET
you have guessed it right, i am copying the text from ms word but am cleaning wordhtml using wordcleaner 3.
further, i checked using
Response.CharSet = "UTF-8"
in this case the ? characters appears on every newline including the places where it was appearing earlier.

when i use
<%Response.CharSet = "Windows-1252"%>

still the problem of question marks remain. but it appears only as was appearing earlier (in place of " and not on every new line)
i checked the view source- the server is sending ? character itself to the browser.
when i checked the database field, it is showing in invalid character in the shape of a rectangle stored where i want the double quote " printed.

please help.
My guess is that they are not " " but are ' " " typically cut'n'pasted in from Microsoft Word.

These are still in the Windows-1252 range of characters but are not strictly in the iso-8859-1 set.

Don't use http-equiv meta tags use real headers instead.

IOW ditch the meta tags and include this:-

<%Response.CharSet = "Windows-1252"%>

I'm not hopeful because you are probably using IE and IE will treat ISO-8859-1 as Windows-1252 anyway.

Always use Server.HtmlEncode on values retrieved from the Database. Stop mucking about with any other approach.

If that doesn't work view the html source from the browser. What is the server actually sending.

Another alternative is stop using Windows-1252.

Save your pages as UTF-8 change the codepage at the top of the page to 65001 and include Response.CharSet = "UTF-8" in your page.

BTW, Have you looked at the field content directly using the DB management tool?


--
Anthony Jones - MVP ASP/ASP.NET
i am attaching the sample code. actually i am printing from a field in access database. the text entered in the database contains single quotes and double quotes. when i try to print them using response.write, the double quotes are getting replaced with question marks. i have tried the method of

DataPrep = Replace(DataPrep, """", "&quot;")

still problem remains.

i also tried
response.write(server.htmlencode(myrs(3))) ' where myrs is adodb recordset

still the problem remains

i am also attaching the header lines from my asp page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

the problem is still not solved

please help
 
A

Anthony Jones

All I'm seeing is a standard apostrophe.

If what you see in the DB is not the character you are expecting then your problem is probably now with the languages you have installed. I don't think all glyphs are installed for each font by default, you need to install the appropriate language for the system to be able to render them.

How is did the data arrive in the DB? Via HTML Form and ASP?




--
Anthony Jones - MVP ASP/ASP.NET
i changed the codepage tp 65001 and charset to utf-8, then the question mark ? showing earlier, has changed to the rectangle as shown below.
'
the database field also shows the same character stored in it.
please help.

My guess is that they are not " " but are ' " " typically cut'n'pasted in from Microsoft Word.

These are still in the Windows-1252 range of characters but are not strictly in the iso-8859-1 set.

Don't use http-equiv meta tags use real headers instead.

IOW ditch the meta tags and include this:-

<%Response.CharSet = "Windows-1252"%>

I'm not hopeful because you are probably using IE and IE will treat ISO-8859-1 as Windows-1252 anyway.

Always use Server.HtmlEncode on values retrieved from the Database. Stop mucking about with any other approach.

If that doesn't work view the html source from the browser. What is the server actually sending.

Another alternative is stop using Windows-1252.

Save your pages as UTF-8 change the codepage at the top of the page to 65001 and include Response.CharSet = "UTF-8" in your page.

BTW, Have you looked at the field content directly using the DB management tool?


--
Anthony Jones - MVP ASP/ASP.NET
i am attaching the sample code. actually i am printing from a field in access database. the text entered in the database contains single quotes and double quotes. when i try to print them using response.write, the double quotes are getting replaced with question marks. i have tried the method of

DataPrep = Replace(DataPrep, """", "&quot;")

still problem remains.

i also tried
response.write(server.htmlencode(myrs(3))) ' where myrs is adodb recordset

still the problem remains

i am also attaching the header lines from my asp page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


<HTML><HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />

the problem is still not solved

please help
 
A

Anthony Jones

S N said:
which group should i consult. please help

This as good a group as any to get help with this issue.

My current guess is that the data has been entered by a Form post via ASP.
In correct codepage settings have corrupted the data entered into the DB.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top