user1064036
user1064036

Reputation: 157

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 );

Upvotes: 1

Views: 1978

Answers (2)

Ben Voigt
Ben Voigt

Reputation: 283634

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);

Upvotes: 1

Steve
Steve

Reputation: 3703

What about this?

byte[] InputbyteArray = Encoding.UTF8.GetBytes(inputString);
string B64String = Convert.ToBase64String(InputbyteArray)

Upvotes: 1

Related Questions