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 );
9
  • What have you tried? Commented Mar 22, 2012 at 9:36
  • What kind of "binary data"? A PNG picture? An integer representing the sum of the ASCII characters in the string? Commented Mar 22, 2012 at 9:45
  • i have a string that I want to convert to base64. I need a byte array in order to use Convert::ToBase64String Commented Mar 22, 2012 at 10:09
  • See stackoverflow.com/questions/5664345/string-to-binary-in-c-sharp (3rd hit on google) Commented Mar 22, 2012 at 10:11
  • You do realize that is C# right? Commented Mar 22, 2012 at 10:28

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

Comments

1

What about this?

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

4 Comments

you say you "found" a solution - an hours after I answered, what is the difference between my answer and your solution?
Your "solution" isn't in the requested language.
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.
Finding someone who knows Managed Extensions for C++ is non-trivial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.