ASP Replace Function....

Reply

Join Date: Nov 2003
Posts: 7
Reputation: vyruzxxx21 is an unknown quantity at this point 
Solved Threads: 0
vyruzxxx21 vyruzxxx21 is offline Offline
Newbie Poster

ASP Replace Function....

 
0
  #1
May 14th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 1,135
Reputation: samaru is just really nice samaru is just really nice samaru is just really nice samaru is just really nice 
Solved Threads: 6
Team Colleague
samaru's Avatar
samaru samaru is offline Offline
a.k.a inscissor

Re: ASP Replace Function....

 
0
  #2
May 24th, 2004
That's to escape apostrophe signs usually in query strings. If you have a query string, let's say something like this:

  1. name = "Lori"
  2. 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:

  1. select * from customers where name = ' Lori '

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

  1. name = "O'Neil"
  2. 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:

  1. 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:

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

And that's why that replace function replaces single apostrophes with doubles.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC