views:

1516

answers:

7

I have a .NET byte[] that is loaded from a file that I happen to known contains UTF-8. In some debugging code, I need to convert it to a string. Is there a one liner that will do this?

Under the covers it should be just an allocation and a memcopy so even if it is not implemented, it should be possible.

+16  A: 
string System.Text.Encoding.UTF8.GetString(byte[])
Zanoni
new guy gets the worm
BCS
@BCS - where were you when I was new? :P
Jon B
aww.. his first accepted answer :)
TStamper
Love how everyone here responds with System.Text.Encoding.UTF8.GetString - lol
Zack
+8  A: 
string str = System.Text.Encoding.UTF8.GetString( arr );
Timbo
+1  A: 

Encoding.UTF8.GetString(byte[] bytes);

dkr88
+4  A: 
String text = System.Text.Encoding.UTF8.GetString(bytes);
Daniel Brückner
+3  A: 
System.Text.Encoding.UTF8.GetString(byteArray);
AlbertEin
A: 

Try this:

protected void Page_Load(object sender, EventArgs e)
{
 byte[] bytearray = (your byte array);
 System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
 Response.Write( encoding.GetString(bytearray)) ;
}
James W
+3  A: 
byte[] b = new byte[100];
string s = System.Text.UTF8Encoding.UTF8.GetString(b);
z-boss