日期:2011-03-03  浏览次数:20528 次

using System;

namespace Joycode.MSN.CommandParsers
{
    /// <summary>
    /// 用户编码解释器
    /// </summary>
    internal class Encoders
    {
        private static System.Text.Encoding enc=System.Text.Encoding.UTF8;
        public Encoders()
        {
            
            
        }
        
        public static int Length(string source)
        {
            
            return enc.GetByteCount(source);
        }
        public static int IndexOf(string source,string find, int start)
        {
            
            
            int result=-1;
            if(start<source.Length)
            {
                
                int index=source.IndexOf(find,start);
                if(index>=0)
                {
                    result=enc.GetByteCount(source.Substring(0,index));
                }
            }
            return result;
        }
        public static int IndexOf(string source, string find)
        {
            //            System.Text.Encoding enc=System.Text.Encoding.UTF8;
            //            int result=enc.GetByteCount(source.Substring(0,source.IndexOf(find)));
            return Encoders.IndexOf(source,find,0);
        }
        public static string Substring(string source,int start,int count)
        {
            //int c=enc.GetByteCount(source);
            string result="";
            try