Is there a way to use ASCIIEncoding in Windows Phone 7?
Unless I\'m doing something wrong Encoding.ASCII doesn\'t exist and I\'m needing it for C# -> PH
I started from @Hans Passant 's answer and I rewrote it with Linq :
///
/// Gets an encoding for the ASCII (7-bit) character set.
///
///
/// A character set.
/// An encoding for the ASCII (7-bit) character set.
public static byte[] StringToAscii(string s)
{
return (from char c in s select (byte)((c <= 0x7f) ? c : '?')).ToArray();
}
You may want to remove the call to ToArray() and return a IEnumerable instead of byte[].