Jon Cage
Jon Cage

Reputation: 37518

How do I convert from a cli::array<unsigned char> to a String?

I have a array<unsigned char>^ which contains a load of ascii characters which I'd like to convert into a String^. What's the most efficient way to do this?

Upvotes: 2

Views: 3110

Answers (1)

Jon Cage
Jon Cage

Reputation: 37518

Found a solution here:

BufferedStream file = gcnew BufferedStream(gcnew FileStream(fileName,FileMode::Open)); 
array<unsigned char>^ arr = gcnew array<unsigned char>(10); 
file->Read(arr,0,10); 

String^ s; 
Text::Encoding^ enc = Text::Encoding::UTF8; 
s = enc->GetString(arr); 

Upvotes: 2

Related Questions