Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASCIIEncoding In Windows Phone 7

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?

like image 764
Dean Avatar asked Oct 26 '10 09:10

Dean


2 Answers

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;
    }
like image 186
Hans Passant Avatar answered Oct 12 '22 12:10

Hans Passant


Not really seeing any detail in your question this could be off track. You are right Silverlight has no support for the ASCII encoding.

However I suspect that in fact UTF8 will do what you need. Its worth bearing in mind that a sequence of single byte ASCII only characters and the same set of characters encoded as UTF-8 are identical. That is the the complete ASCII character set is repeated verbatim by the first 128 single byte code points in UTF-8.

like image 42
AnthonyWJones Avatar answered Oct 12 '22 11:10

AnthonyWJones