View Code
using System;
using System.Text;

namespace StringLengthTest
{
    class Program
    {
        static void Main(string[] args)
        {

            string strTmp = "abcd1234软件包";
            int i = Encoding.GetEncoding("GB2312").GetBytes(strTmp).Length;
            int j = Encoding.Unicode.GetBytes(strTmp).Length;
            int m = Encoding.ASCII.GetBytes(strTmp).Length;
            int n = Encoding.Default.GetBytes(strTmp).Length;
            int k = Encoding.UTF8.GetBytes(strTmp).Length;
            Console.WriteLine(strTmp);
            Console.WriteLine("GB2312: " + i);
            Console.WriteLine("Unicode:" + j);
            Console.WriteLine("ASCII:  " + m);
            Console.WriteLine("Default:" + n);
            Console.WriteLine("UTF8:   " + k);
            Console.ReadKey();

        }
    }
}

运行结果:

abcd1234软件包
GB2312: 14
Unicode:22
ASCII:  11
Default:14
UTF8:   17

 

 posted on 2012-05-08 18:05  Lucien.Bao  阅读(275)  评论(0编辑  收藏  举报