-1

I encode string in c# using this code

System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding();
byte[] asciiBytes =encoding.GetBytes(result);

but I cant decode asciibytes to string can any one help me??

Anri
  • 6,175
  • 3
  • 37
  • 61
  • You would just reverse it: `string text = encoding.GetString(asciiBytes)`. Note that `asciiBytes` is very badly named, however - UTF-8 != ASCII. Also, I'd typically use `Encoding.UTF8` rather than creating a new `UTF8Encoding`. – Jon Skeet Feb 09 '14 at 07:09

1 Answers1

0

encoding.GetString(asciiBytes) In some .NET versions this extension methode is not available so you have to use: encoding.GetString(asciiBytes, 0, asciiBytes.Length)

Another note: ASCII and UTF-8 are not the same. So the wording asciiBytes is a bit confusing.

You can also use the static instance instead of creating an encodingobject.

Encoding.UTF8.GetBytes(..)

http://msdn.microsoft.com/en-us/library/744y86tc(v=vs.110).aspx

wollnyst
  • 1,683
  • 1
  • 17
  • 20
  • `Encoding.GetString(byte[])` isn't an extension method - it's just a normal method which has been available since .NET 1.0. It's not available in the PCL/Silverlight/Windows Phone, but that's slightly different. – Jon Skeet Feb 09 '14 at 07:10