1

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 );
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
user1064036
  • 157
  • 4
  • 11

2 Answers2

1

What about this?

byte[] InputbyteArray = Encoding.UTF8.GetBytes(inputString);
string B64String = Convert.ToBase64String(InputbyteArray)
Steve
  • 3,673
  • 1
  • 19
  • 24
  • you say you "found" a solution - an hours after I answered, what is the difference between my answer and your solution? – Steve Mar 22 '12 at 12:59
  • Your "solution" isn't in the requested language. – Ben Voigt Mar 22 '12 at 18:17
  • I disagree, it was a .net question not a c++ or clr specific question. The solution is .net, just different syntax - which lets be honest is a trivial conversion. – Steve Mar 22 '12 at 19:25
  • Finding someone who knows Managed Extensions for C++ is non-trivial. – Ben Voigt Mar 22 '12 at 19:50
1

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);
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720