获取字符串长度(中文*2英文*1)

获取字符串的字符长度

 1         #region "获取字符串长度(中文*2英文*1)"
 2         /// <summary>
 3         /// 返回字符串的Ascii字符数量
 4         /// </summary>
 5         /// <param name="strCode">查询字符串</param>
 6         /// <returns>Ascii字符数</returns>
 7         public static int getStrLen(string strCode)
 8         {
 9             int _strlength = strCode.Length;
10             int tmpNum = 0;
11 
12             byte[] strASCII = ASCIIEncoding.ASCII.GetBytes(strCode);
13             for (int i = 0; i < _strlength; i++)
14             {
15                 if ((int)strASCII[i] == 63)
16                 {
17                     tmpNum += 2;
18                 }
19                 else
20                 {
21                     tmpNum += 1;
22                 }
23                 if (i == _strlength - 1break;
24             }
25             return tmpNum;
26         }
27         #endregion
posted @ 2006-11-06 11:25  星痕  阅读(319)  评论(0编辑  收藏  举报