0

Possible Duplicate:
ASCIIEncoding In Windows Phone 7

I am working with Windows Phone 8, and I have noticed that Encoding.ASCII doesn't exist in .NET for Windows Phone, but there is a class called ASCIITools, which contains a method called StringToAscii. which returns a byte array and accepts a string.

I ask because I am trying to convert some code which initially gets a character array from a string like this:

char[] myCharArray = blah.Substring(aaa, bbb).ToCharArray();

And then gets the byte array from the char array by passing it into the GetBytes method:

byte[] blah = Encoding.ASCII.GetBytes(myCharArray, 0, myCharArray.Length);

It looks like this class will allow me to go directly from a string to a byte array like so:

byte[] blah = ASCIITools.StringToAscii(blah.Substring(aaa, bbb));

Will this work?

Community
  • 1
  • 1
JMK
  • 27,273
  • 52
  • 163
  • 280
  • Probably using Encoding.UTF8 will solve your problem, but you can always use the [Silverlight Encoding Generator][1] and get any encoding you'd like! [1]: http://www.hardcodet.net/2010/03/silverlight-text-encoding-class-generator – Pedro Lamas Dec 31 '12 at 20:53
  • Test it out! Messagebox.Show(Encoding.Ascii.GetBytes(myCharArray, 0, myCharArray.Length) + Enviroment.NewLine + ASCIITools.StringToAscii(myCharArray.ToString()); – It'sNotALie. Dec 31 '12 at 22:03

0 Answers0