Visual c++ Express .net base64 Functions
- 0 Comments
This problem is two fold. First it solves the problem of converting a string to and from base64, and it shows how to create a function that is not part of the objects in the application. By that, I mean, a function that isn’t created for you by Express when you click on an object in the visual editor.
I only mention this because I ran into a situation where I couldn’t figure out how to make a function in c++ .net. It have everything to do with the fact that all variables require a ^. They are even included when defining the return type of a function.
Anyway, here’s the two functions to convert to and from base64.
private: System::String^ toBase64( System::String^ from )
{
System::Text::ASCIIEncoding^ encoding = gcnew System::Text::ASCIIEncoding();
System::String^ base64 = System::Convert::ToBase64String(encoding->GetBytes(from));
//change 0 to a 2 if you want to cut off ==
return base64->Substring(0,base64->Length-0);
}
private: System::String^ fromBase64( System::String^ from )
{
System::Text::ASCIIEncoding^ encoding = gcnew System::Text::ASCIIEncoding();
array
return encoding->GetString(base64);
}

