Convert String to char[]

K

Kueishiong Tu

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?
 
J

Jon Skeet

Kueishiong Tu said:
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?

What exactly do you mean by "a native char[] type"?

To get the string as a .NET char array, use String.ToCharArray. To get
the string encoded into a byte array, use Encoding.GetBytes.
 
J

Jon Skeet

Kueishiong Tu said:
What exactly do you mean by "a native char[] type"?

the original char array type in c or c++ (not managed);

Right - in other words, a byte array.
To get the string as a .NET char array, use
String.ToCharArray.

The compiler required the char array copied to to be
of the type '__wchar_t __gc[]' which is managed.

Ah, if it's __wchar_t[], you might be okay with the .NET char[] type.
Unless I'm much mistaken (which I may well be), __wchar_t is a Unicode
char.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top