zoukankan      html  css  js  c++  java
  • 计算字符串长度

    -(NSUInteger) unicodeLengthOfString: (NSString *) text//汉字长度  2个英文字母=1个汉字

    {

        NSUInteger asciiLength = 0;

        

        for (NSUInteger i = 0; i < text.length; i++)

        {

            unichar uc = [text characterAtIndex: i];

            asciiLength += isascii(uc) ? 1 : 2;

        }

        NSUInteger unicodeLength = asciiLength / 2;

        if(asciiLength % 2)

        {

            unicodeLength++;

        }

        return unicodeLength;

    }

    -(NSUInteger) asciiLengthOfString: (NSString *) text//一个汉字2字节

    {

        NSUInteger asciiLength = 0;

        

        for (NSUInteger i = 0; i < text.length; i++)

        {

            unichar uc = [text characterAtIndex: i];

            asciiLength += isascii(uc) ? 1 : 2;

        }

        return asciiLength;

    }

  • 相关阅读:
    jmeter 建立一个扩展LDAP测试计划
    jmeter 构建一个Web测试计划
    python 练习 29
    python 练习 28
    Python 练习 31
    python 练习 30
    python 练习 26
    python 练习 25
    python 练习24
    python 练习 23
  • 原文地址:https://www.cnblogs.com/swallow37/p/3060865.html
Copyright © 2011-2022 走看看