using System;
using System.Collections.Generic;
using System.Text;

namespace BLL
{
    /// <summary>
    /// 系统转换类
    /// 王彬        2011-09-13
    /// </summary>
    public class SysConvert
    {

        #region 三个字符(0-9,A-Z,a-z)
        /// <summary>
        /// 三个字符自动加一,从0-9,A-Z,a-z
        /// 例如: Aab==SysConvert.getAdd(Aaa);
        /// </summary>
        /// <param name="word">三个字符(0-9,A-Z,a-z)</param>
        /// <returns>三个字符加一后的结果</returns>
        public static string getAdd(string word)
        {

            char[] charArray = word.ToCharArray();

            string str_asciicode0 = charArray[0].ToString();
            string str_asciicode1 = charArray[1].ToString();
            string str_asciicode2 = charArray[2].ToString();

            str_asciicode2 = SysConvert.getAddOne(str_asciicode2);  //个位加一

            if (str_asciicode2 == "0")
            {          //如果个位等于z(ascii:122),则十位加一
                str_asciicode1 = SysConvert.getAddOne(str_asciicode1);
            }
            if (str_asciicode1 == "0")
            {          //如果十位等于z(ascii:122),则百位加一
                str_asciicode0 = SysConvert.getAddOne(str_asciicode0);
            }

            return str_asciicode0 + str_asciicode1 + str_asciicode2;
        }
        /// <summary>
        /// 取得ASCII码
        /// </summary>
        /// <param name="word">正常的数字或字母</param>
        /// <returns>ASCII码</returns>
        public static int getAscii(string word)
        {
            byte[] array = new byte[1];
            array = System.Text.Encoding.ASCII.GetBytes(word);
            return (short)(array[0]);
            //    int asciicode0 = (short)(array[0]);
            //    return Convert.ToString(asciicode0);
        }

        /// <summary>
        /// ASCII码变换成字母或数字
        /// </summary>
        /// <param name="asciicode">ASCII码</param>
        /// <returns>正常的数字或字母</returns>
        public static string getWord(int asciicode)
        {
            byte[] array = new byte[1];
            array[0] = (byte)(asciicode); //ASCII码强制转换二进制
            return Convert.ToString(System.Text.Encoding.ASCII.GetString(array));
        }

        /// <summary>
        /// 自动加一,从0-9,A-Z,a-z
        /// </summary>
        /// <param name="ascii"></param>
        /// <returns></returns>
        public static string getAddOne(string word)
        {
            int ascii = SysConvert.getAscii(word);      //取出ASCII码
            int result = 0;                              //返回结果

            if (ascii == 57)
            {                            //9
                result = 65;
            }
            else if (ascii == 90)
            {                        //Z
                result = 97;
            }
            else if (ascii == 122)
            {                     //z
                result = 48;
            }
            else
            {                 //除了上面的任意字母或数字
                result = ++ascii;
            }

            return SysConvert.getWord(result);
            //return Convert.ToString(result);
        }

        #endregion

    }
}

  

posted on 2011-09-13 10:57  Dufe王彬  阅读(597)  评论(0编辑  收藏  举报