如何从cli :: array <unsigned char =“”>转换为String?</unsigned>

时间:2012-10-04 09:29:06

标签: .net arrays c++-cli

我有一个array<unsigned char>^,其中包含一些ascii字符,我想将其转换为String^。什么是最有效的方法?

1 个答案:

答案 0 :(得分:2)

找到解决方案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);