本帖最后由 ok2ok2ok2 于 2011-03-31 11:55:27 编辑

解决方案 »

  1.   


    string str = "abc";
    for(int i = 0; i < str.Length; i++)
     Console.WriteLine((int)str[i]);应该是这样
      

  2.   

    写个demo吧:foreach (char c in s.ToArray())
        Console.Write("{0} ", (int)c);
      

  3.   

    System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
    int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0];
      

  4.   

    //字符串转换为ascii码
                string s = "abc";
                byte[] byteArray = new byte[s.Length];
                byteArray = ASCIIEncoding.ASCII.GetBytes(s);
                string p = "";
                for (int i = 0; i < byteArray.Length; i++)
                {
                    p = p + byteArray[i]+",";
                }
                s = p;
                //ascii码转换为字符串
                int aa = 44;
                byte[] ss = new byte[]{(byte)aa};
                string sp=ASCIIEncoding.ASCII.GetString(ss);
                s = sp;
      

  5.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace tmp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string s = "hello world!";
                foreach (char c in s.ToCharArray())
                {
                    Console.Write("{0}   {1}\n",(int)c,c);
                }            Console.WriteLine("------------------------\n");
                int i = 0;
                while (i < s.Length)
                {
                    Console.Write("{0}   {1}\n",(int)s[i],s[i]);
                    i++;
                }
                Console.ReadLine();
            }
        }
    }
      

  6.   

    abc到底是什么?
    如果只是字符串的话,string s = "abc";
    用索引取就行了
    s[0],s[1],s[2]
      

  7.   

    谢谢,为什么要这么复杂呢?
    道理是什么。
    上面有更简单的代码:(int)s[i]
    我想问,你用这么复杂的代码,必要性何在呢?请再指教
      

  8.   


    容易读懂,知道在干嘛。不会转化为Utf8之类的