Search code examples
.netvisual-c++managed-c++

how can I convert string to binary data using .net


How can I convert a string variable to a binary data variable using .net 1.1?

I found a way of doing this:

ASCIIEncoding^ ascii = gcnew ASCIIEncoding;
String^ unicodeString = L"This Unicode String* contains two characters with codes outside the ASCII code range, Pi (\u03a0) and Sigma (\u03a3).";
array<Byte>^ binaryData = ascii->GetBytes( unicodeString );

Solution

  • In .NET 1.1, you only have access to the broken Managed Extensions for C++ compiler. It is broken, you should not use it.

    However, IIRC, the syntax would be something like:

    System::Byte bytes __gc[] = Encoding::ASCII::GetBytes(inputString);
    System::String __gc* base64string = Convert::ToBase64String(bytes);