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!
C++

Avatar of undefined
Last Comment
PMH4514

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
jkr

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
wayside

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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.
jkr

Hm, I guess '_tcschr()' has already been mentioned ;o)
wayside

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.   ;)
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
PMH4514

ASKER
I'm not sure there's anything either of you doesn't know about C++
:-)
DanRollins

>> 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.
PMH4514

ASKER
yes sorry I mis-typed.. two apostrophies. :)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.