In general case, the text cannot be "converted" into ASCII, because .NET supports Unicode, and ASCII only supports Unicode characters with code points below 127.
Just
forget ASCII, it's gone; use any of the UTF encodings.
Remember that they are all equivalent, but resulting binary code is different (in memory, Unicode is represented using UTF16LE). And this is not a bit array, but array of bytes. (You never need a bit array anyway). You need to use
System.Text.Encoding.ToBytes(string)
to get byte array and
System.Text.Encoding.GetChars
to go back to string again (use resulting char array as the argument of a
string
constructor:
http://msdn.microsoft.com/en-us/library/ds4kkd55.aspx[
^],
http://msdn.microsoft.com/en-us/library/khac988h.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx[
^],
http://msdn.microsoft.com/en-us/library/ttyxaek9.aspx[
^].
Of course, you will need to use one of concrete UTF classes derived from the abstract class
Encoding
; I would prefer UTF-8 as the most compact, especially if many characters of your text are withing the ASCII
repertoire, which is most typically the case. Also, this UTF is the standard for most application fields.
—SA