ASCIIEncoding In Windows Phone 7

前端 未结 6 575
甜味超标
甜味超标 2020-12-01 16:18

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

6条回答
  •  醉酒成梦
    2020-12-01 16:54

    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[].

提交回复
热议问题