Link to home
Start Free TrialLog in
Avatar of PMH4514
PMH4514

asked on

C++ TCHAR string replacement?

I have a TCHAR variable holding a string that contains an apostrophe.  I need to turn it into a double quote for insertion into a SQL command.. Normally with CString I use Replace(..) but I can't seem to find a way to do it on the TCHAR.. I could convert it to a string, replace and convert back but that seems wasteful.

thanks!
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wayside
wayside

If you really don't want to use a string class, you can:

- repeatedly use _tcschr() to find all the characters you want to replace and manually replace it;

- walk the characters of the string yourself in a for loop or while loop, looking for the one you want to replace, and manually replacing it.
Hm, I guess '_tcschr()' has already been mentioned ;o)
Hmm, you'd think I'd have learned by now to refresh before I hit the submit button, because the odds of me beating you to a solution are so low.   ;)
Avatar of PMH4514

ASKER

I'm not sure there's anything either of you doesn't know about C++
:-)
>> I need to turn it into a double quote for insertion into a SQL command..
Don't you mean that you need to convert it into two apostrophes?  In SQL statements, a double quote (") is a very different thing from two adjacent single quote (') characters (apostrophes).  The SQL parser treats '' (two apostrophes) as one apostrophes.  That is probably what you need to do.
Avatar of PMH4514

ASKER

yes sorry I mis-typed.. two apostrophies. :)