Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to eliminate special character in my cstring?

711 views
Skip to first unread message

samuel

unread,
May 3, 2003, 4:18:18 AM5/3/03
to

My String contains one special character like '.
It makes me fail to transfer string to buffer.

How can I eliminate this special character ' in my
cstring?

thanks.

Simon

unread,
May 3, 2003, 9:18:46 AM5/3/03
to
try
int CString::Remove(TCHAR ch);??


"samuel" <samb...@hotmail.com> ??????:041101c3114c$8d5ee8e0$a301...@phx.gbl...

Joseph M. Newcomer

unread,
May 3, 2003, 12:03:57 PM5/3/03
to
What do you mean "makes me fail to transfer string to buffer"? Show the code and explain
what went wrong. Normally, transfers of strings "to buffers" is a simple copy, and in many
cases, there was never a need to do a "transfer" because the CString could be used
directly (but the programmer doesn't know this).
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

lallous

unread,
May 5, 2003, 2:48:50 AM5/5/03
to
> What do you mean "makes me fail to transfer string to buffer"? Show the
code and explain
> what went wrong.
Maybe he's using the value of the CString to issue an SQL query and having
the single quote character will cause the query to fail, unless he escapes
that single quote.

Regards,
Elias


Tim

unread,
May 5, 2003, 5:12:16 AM5/5/03
to
If you want to remove a character, use Replace to replace it with a zero
length string:

CStrings str;
str = _T("ABCDE'FGH");
str.Replace(_T("'"), _T("")); // " ' " replaced by empty string
TRACE(str);

or, if you are using the string in SQL as suggested, then you can 'stuff'
the single quote with 2 - which is then accepted:

CStrings str;
str = _T("ABCDE'FGH");
str.Replace(_T("'"), _T("''")); // " ' " replaced by " ' ' " - no spaces
inside quotes.
TRACE(str);

- Tim


"samuel" <samb...@hotmail.com> wrote in message
news:041101c3114c$8d5ee8e0$a301...@phx.gbl...

Joseph M. Newcomer

unread,
May 19, 2003, 12:30:56 AM5/19/03
to
But in that case it is obvious what to do: use Replace. But in that case I would have
expected a question about how to deal with special characters in a SQL query.
joe

Joseph M. Newcomer [MVP]

lallous

unread,
May 19, 2003, 6:34:42 AM5/19/03
to
<?
$str = '
dHJ5IA0KaW50IENTdHJpbmc6OlJlbW92ZShUQ0hBUiBjaCk7Pz8NCg0KDQoic2FtdWVsIiA8c2Ft
YnVlbGFAaG90bWFpbC5jb20+ID8/Pz8/PzowNDExMDFjMzExNGMkOGQ1ZWU4ZTAkYTMwMTI4MGFA
cGh4LmdibC4uLg0KPiANCj4gTXkgU3RyaW5nIGNvbnRhaW5zIG9uZSBzcGVjaWFsIGNoYXJhY3Rl
ciBsaWtlICcuDQo+IEl0IG1ha2VzIG1lIGZhaWwgdG8gdHJhbnNmZXIgc3RyaW5nIHRvIGJ1ZmZl
ci4NCj4gDQo+IEhvdyBjYW4gSSBlbGltaW5hdGUgdGhpcyBzcGVjaWFsIGNoYXJhY3RlciAnIGlu
IG15IA0KPiBjc3RyaW5nPw0KPiANCj4gdGhhbmtzLg0KPiA=';
echo base64_decode($str);
?>
/*
Output is:
-------------


"samuel" <samb...@hotmail.com> ??????:041101c3114c$8d5ee8e0$a301...@phx.gbl...

> Press any key to continue . . .
*/

0 new messages