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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.