zoukankan      html  css  js  c++  java
  • 获取字符串(包括汉字)的长度

    参考: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
  • 相关阅读:
    ASP.NET Web应用程序与ASP.NET Web服务应用程序的区别
    【你必须知道的.NET】:【大话String】
    获取SQLServer数据库中所有表
    Window_Open详解收藏
    关于数据实现批量删除
    asp.net mvc 图形解析说明原理
    【转载】:C#语言
    泛型参数的约束
    SQL 常用函数小结
    [转载]:C#两种不同的存储过程调用方法
  • 原文地址:https://www.cnblogs.com/wuming/p/1423422.html
Copyright © 2011-2022 走看看