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
  • 相关阅读:
    php生成二维码遇到的问题
    ua判断页面在什么终端/系统打开
    js实现复制文字到剪切板
    jquery 实现表单数据转化为对象格式
    [转]关于setTimeout()你所不知道的地方
    关于性能优化
    关于event loop
    JS数据结构与算法--双向链表
    JS数据结构与算法--单向链表
    JS数组去重
  • 原文地址:https://www.cnblogs.com/wuming/p/1423422.html
Copyright © 2011-2022 走看看