• category应用(计算nssting的数量)


    //

    //  main.m

    //  03-分类应用

    //

    //  Created by apple on 14-3-18.

    //  Copyright (c) 2014年 apple. All rights reserved.

    //

    #import <Foundation/Foundation.h>

    /*

     统计一个字符串中,出现的整数的个数

     */

    #import "NSString+NSStringExtend.h"

    int main(int argc, const char * argv[])

    {

        @autoreleasepool {

            

    //        NSString * str = @"ab1d3,5,5,4";

    //        

    //        int count = [NSString numberCountOfString:str];

    //        NSLog(@"%d",count);

    //        NSString * str = @"adf378";//字符串对象

    //        

    //        

    //        NSLog(@"new %d",[@"adf378" numberOfCount]);

            

            

            int count = [NSString numberCountOfString:@"12345"];

            NSLog(@"%d",count);

        }

        return 0;

    }

    //

    //  NSString+NSStringExtend.m

    //  02-OC中特有的一些语法

    //

    //  Created by apple on 14-3-18.

    //  Copyright (c) 2014年 apple. All rights reserved.

    //

    #import "NSString+NSStringExtend.h"

    @implementation NSString (NSStringExtend)

    //ab1c890

    + (int)numberCountOfString:(NSString *)str

    {

        /*

        int count = 0;

        //1.把每一个字符拿出来比较

        for (int i = 0; i < str.length; i++)

        {

          unichar c = [str characterAtIndex:i];

          

            if (c >= '0' && c <= '9' )

            {

                count++;

            }     

            

        }

        

        return count;

         */

        

        return [str numberOfCount];

    }

    - (int)numberOfCount

    {

        int count = 0;

        //1.把每一个字符拿出来比较

        for (int i = 0; i < self.length; i++)

        {

            unichar c = [self characterAtIndex:i];

            

            if (c >= '0' && c <= '9' )

            {

                count++;

            }

            

        }

        return count;

    }

    @end

  • 相关阅读:
    不装JDK环境运行项目jar包
    java 开发事务回滚
    navicat无法连接MySql; client does not support authentication....
    java url特殊字符报400
    修复windows **.dll缺失
    mysql5.7解压版安装
    IDEA破解
    java 通过request.getParameterMap()获取前台传入参数
    java 实现https请求
    java 实现Http请求
  • 原文地址:https://www.cnblogs.com/supper-Ho/p/6172037.html
Copyright © 2020-2023  润新知