Sign in to follow this  

[.net] convert string to char array (mc++/cli)

This topic is 4241 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

System::String^ s = "DeviceInfo"; array<wchar_t,1>^ unicodeArray = s->ToCharArray(); array<unsigned char,1>^ charArray= System::Convert::FromBase64CharArray(unicodeArray ,0 /*offset*/,unicodeArray ->Length); compiles without warnings. No casting required. Length returns 10. Error: Invalid length for a Base-64 char array. im lost, this should work as far as i can see. Anybody any ideas?

Share this post


Link to post
Share on other sites
The problem is that your unicodeArray is not a base 64 char array (uuencoded). A true base 64 char array must be a multiple of 4 bytes long and have base 64 characters in it. A standard System::String doesn't have base 64 characters.

I'm not sure I understand what you are trying to do. If all you want to do is convert a System::String to an array of characters (System::Char[]), all you need is the ToCharArray().

Share this post


Link to post
Share on other sites
yeah, your right, oops.

However i know i can convert to a character array with ToCharArray() but that returns a unicode 16 bit character.

There are infact file write methods which take 8 bit byte streams. How do i convert to 8 bit characters?

Share this post


Link to post
Share on other sites
.Net strings are Unicode capable. To get bytes you need to use a System.Text.Encoding class, e.g. byte[] bytes = Encoding.UTF8.GetBytes(myString).

Share this post


Link to post
Share on other sites

This topic is 4241 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this