I think you can guess the problem I'm having. I'm inserting filenames in to an sql database in C++ Builder. Some files have an apostrophe in their name. This breaks the sql insert query. the usual way to fix this is to double up and apostrophes you want to be part of the field value.
For example if I want to add 'george's' to field 'owner' the sql query would be "insert into table (owner) values ('george''s')"
I'm ok with that bit. I just need to get the single apostrophes replaced with double ones. AnsiString doesn't seem to have a built in function for this. Is there a simple way to do it without having to include a whole new header file?
Actually I got the answer by myself...
item = StringReplace( item, "'", "''", TReplaceFlags() <<rfReplaceAll );
(so there is a built in replace function in AnsiString afterall)
Edit: Added code tags so we can distinguish between different quotes
I haven't used AnsiString, but basically I'd do the following:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With