943,865 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 57185
  • ASP RSS
May 14th, 2004
0

ASP Replace Function....

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vyruzxxx21 is offline Offline
7 posts
since Nov 2003
May 24th, 2004
0

Re: ASP Replace Function....

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

ASP Syntax (Toggle Plain Text)
  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:

ASP Syntax (Toggle Plain Text)
  1. select * from customers where name = ' Lori '

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

ASP Syntax (Toggle Plain Text)
  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:

ASP Syntax (Toggle Plain Text)
  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:

ASP Syntax (Toggle Plain Text)
  1. select * from customers where name = ' O''Neil '

And that's why that replace function replaces single apostrophes with doubles.
Team Colleague
Reputation Points: 262
Solved Threads: 18
a.k.a inscissor
samaru is offline Offline
1,227 posts
since Feb 2002

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: "ADODB Recordset error"
Next Thread in ASP Forum Timeline: force Search Page to return no records on open





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC