无名

长风破浪会有时,直挂云帆济沧海!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
参考:http://msdn.microsoft.com/zh-cn/library/system.globalization.unicodecategory.aspx
 1      public static int GetStringLengthByChar(String origin)
 2        {
 3            Int32 strLength = 0;
 4            if(!String.IsNullOrEmpty(origin))
 5            {
 6                foreach (char c in origin)
 7                {
 8                    UnicodeCategory testC = char.GetUnicodeCategory(c);
 9                    switch (testC)
10                    {
11                        case UnicodeCategory.OtherLetter:
12                            strLength += 3;
13                            break;
14                        case UnicodeCategory.UppercaseLetter:
15                            strLength += 2;
16                            break;
17                        default:
18                            strLength += 1;
19                            break;
20                    }

21                }

22            }

23            return strLength;
24        }

25
posted on 2009-03-27 18:55  无名  阅读(443)  评论(0编辑  收藏  举报