473,391 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,391 software developers and data experts.

How to convert String to char

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
4 11280
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Trep | last post by:
Hi there! I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003. This is necessary because I...
5
by: IamZadok | last post by:
Hi I was wondering if anyone knew how to convert a string or an integer into a Static Char. Thx
7
by: MilanB | last post by:
Hello How to convert char to int? Thanks
15
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
12
by: Brian Henry | last post by:
first question... I have a flat file which unfortinuatly has columns seperated by nulls instead of spaces (a higher up company created it this way for us) is there anyway to do a readline with this...
2
by: Steve Kershaw | last post by:
I can convert from a string to a char array (char) by using string.ToCharArray() function. Now how do I convert it back? The string looks like this: "000457". I've converted it to a char array:...
5
by: Zytan | last post by:
I am surprised that a single character string is not auto-created from a single char. It is hard to find information on converting a char into a string, since most people ask how to convert char...
4
by: Man4ish | last post by:
HI , I am trying to convert string into char array of characters.but facing problem. #include <iostream> #include <string> using namespace std; int main() { string t="1,2,3,4,5,6";
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
14
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.