Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing a double quote 1

Status
Not open for further replies.

Garabaldi

Technical User
Jan 16, 2002
61
CA
Hi Folks,

I have a textbox. In this text box i have users who insist on using double quotes ("). I want to strip out the double quotes before i write it to the database otherwise it screws up my query.

I've tried the string replace.

value = Replace(value,""","")

but it generates an error.

Anyone have any clue on how to do this???

Thanks,
 
Hi RhythmAddict112,

I tried that... and it seems to have no effect.

Maybe I should point out that the value people are entering are things like: the error message is "one two buckle my shoe".

How do i strip those two double quotation marks so it doesn't mess up my sql??

Thanks

 
Do you always display the strings on the ASP? Then you can use HTMLencode:
value = Server.HTMLEncode(value)

or do this:
value=replace(value, chr(34),""")

Best wishes,
Andy

[blue]An eye for an eye only ends up making the whole world blind. - "Mahatma" Mohandas K. Gandhi[/blue]
 
well double quotes in text boxes/text areas wont affect string statements, as for SQL your big issue will be with single quotes like : "ryan parson's dog"

will break SQL, you will need a replace on the single quotes to fix that, and for giggles i've added the additional double quote handling for "just in case" issues :
Code:
[green]' The on error resume next's are just in case you feed the functions a NULL value or something odd it doesn't like in the replace function [/green]

Function SQLQuotes(StringValue)
On Error Resume Next
    SQLQuotes = Trim(Replace(StringValue,"'","''"))
End Function

Function AllQuotes(StringValue)
On Error Resume Next
'chr(34) is standard double quote
    AllQuotes = Trim(Replace(Replace(StringValue,Chr(34),Chr(34) & Chr(34)),"'","''"))
End Function

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Garabaldi, I don't think you actually tried what RhythmAddict suggested... you example has three double-quotes in a row in the first part of the replace, but RA's has four, the correct number. And it most definitely will replace actual double-quotes with nothing.

It's possible that your users are copying and pasting text from a word processor, in which case you might have curly left-quotes and curly right-quotes in there, totally different ASCII characters.
 
Drexor why do use on resume next over
Code:
Function sq(stext)
 If sText <> "" then sq = Replace(stext,"'","''")
End Function 
['code]

                        [b]www.sitesd.com[/b]
                    ASP WEB DEVELOPMENT
 
saves typing? :)

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top