954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ASP Replace Function....

Hi techies, I have searched so many "Replace" function topics, but there is something that I don't understand....I found some like this... Replace(strField, " ' ", " ' ' ") .... do anyone knows what's the use of replaceing ' with ' ' ? Tnx in advance.

vyruzxxx21
Newbie Poster
7 posts since Nov 2003
Reputation Points: 10
Solved Threads: 0
 

That's to escape apostrophe signs usually in query strings. If you have a query string, let's say something like this:

name = "Lori"
sql = "select * from customers where name = ' " & name & " ' "


There won't be a problem. The sql statement, after it's been merged with the variable name will look like this:

select * from customers where name = ' Lori '


Which is a perfectly legit SQL statement. BUT if you had something like this:

name = "O'Neil"
sql = "select * from customers where name = ' " & name & " ' "


It would crap out because of that apostrophe sign in O'Neil. So the SQL statement will look like this:

select * from customers where name = ' O'Neil '


Which the database will think the apostrophe after the O is the end of the SQL statement and will wonder about the trailing "Neil" - how do you fix this? You escape the apostrophe sign by double it. So it would look like this:

select * from customers where name = ' O''Neil '


And that's why that replace function replaces single apostrophes with doubles.

samaru
a.k.a inscissor
Team Colleague
1,256 posts since Feb 2002
Reputation Points: 262
Solved Threads: 18
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You