Jump to content
  • Advertisement
Sign in to follow this  
Riviera Kid

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

This topic is 4516 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!