By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,507 Members | 1,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,507 IT Pros & Developers. It's quick & easy.

How to convert String to char

P: n/a
How do I convert a managed String type to a native char
type? If nothing is availbale, how do I copy the the
contents of the String object to a char array?
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
String* str = S"Hello world";
char c = (char)str->Chars[0];

--
Regards,
Nish [VC++ MVP]

"Kueishiong Tu" <ks****@seed.net.tw> wrote in message
news:0b****************************@phx.gbl...
How do I convert a managed String type to a native char
type? If nothing is availbale, how do I copy the the
contents of the String object to a char array?

Nov 16 '05 #2

P: n/a
Hi Nishant,
String* str = S"Hello world";
char c = (char)str->Chars[0];


Well, that's one cast I'd stay away from, if you want your app to work when
"special" characters are in the string (remember that System::String is
UTF-16 encoded, while you are only handling 8-bit characters in char)

--
Tomas Restrepo
to****@mvps.org
Nov 16 '05 #3

P: n/a
Dear Nish:
I tried it and it worked. As a matter of fact, I need to
convert the whole string. So I just put it in a loop.
Thank you very much.

Kueishiong Tu
Nov 16 '05 #4

P: n/a
Yup I know. But since he specifically wanted to cast to a char I guess we
can assume he wont be handling special characters.

--
Regards,
Nish [VC++ MVP]

"Tomas Restrepo (MVP)" <to****@mvps.org> wrote in message
news:#U*************@TK2MSFTNGP11.phx.gbl...
Hi Nishant,
String* str = S"Hello world";
char c = (char)str->Chars[0];
Well, that's one cast I'd stay away from, if you want your app to work

when "special" characters are in the string (remember that System::String is
UTF-16 encoded, while you are only handling 8-bit characters in char)

--
Tomas Restrepo
to****@mvps.org

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.