views:

48

answers:

3

Is there a Way to use ASCIIEncoding in Windows Phone 7?

Unless im 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?

Thanks.

A: 

According to this MS forum thread, Windows Phone 7 does not support Encoding.ASCII.

Mitch Wheat
Well, Is there other ways around this (E.G. Custom Class or Library)? Or does the Framework itself have to support ASCII?
Dean
+1  A: 

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.

AnthonyWJones
+3  A: 

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;
    }
Hans Passant
Thanks, Ill give it a go...
Dean
Thanks, Work Perfectly.
Dean