How to convert a string to ASCII Encoding in C#

1 Answer

0 votes

using System;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "ASCII Encoding in C#";

            byte[] ascii = Encoding.ASCII.GetBytes(s);
            foreach (byte b in ascii)
                Console.Write(b + " "); 
        }
    }
}

/*
run:
  
65 83 67 73 73 32 69 110 99 111 100 105 110 103 32 105 110 32 67 35
 
*/


answered Feb 22, 2015 by avibootz

Related questions

1 answer 158 views
158 views asked Jan 27, 2024 by avibootz
1 answer 320 views
1 answer 196 views
1 answer 134 views
134 views asked Apr 2, 2021 by avibootz
...