ASCIIEncoding In Windows Phone 7

ascii, c#, encoding, windows-phone-7

Solution

It is easy to implement yourself, Unicode never messed with the ASCII codes:

    public static byte[] StringToAscii(string s) {
        byte[] retval = new byte[s.Length];
        for (int ix = 0; ix < s.Length; ++ix) {
            char ch = s[ix];
            if (ch <= 0x7f) retval[ix] = (byte)ch;
            else retval[ix] = (byte)'?';
        }
        return retval;
    }

Problem

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# -> PHP encryption (as PHP only uses ASCII in SHA1 encryption). Any suggestions?

Original source