NSString Category

毋城
2023-12-01

一. 截取数字并组成字符串.

//
//  NSString+InterceptCharacter.h
//  IosLibrary
//
//  Created by skychi on 13-5-30.
//  Copyright (c) 2013年 skychi. All rights reserved.
//

#import <Foundation/Foundation.h>
//截取字符
@interface NSString (InterceptCharacter)
-(NSString *) interceptDigit;
@end


//
//  NSString+InterceptCharacter.m
//  IosLibrary
//
//  Created by skychi on 13-5-30.
//  Copyright (c) 2013年 skychi. All rights reserved.
//

#import "NSString+InterceptCharacter.h"

@implementation NSString (InterceptCharacter)


#pragma mark - InterceptDigit
-(NSString *) interceptDigit{
    int n = [self length];
    NSString *digitString  = @"";
    unichar c;
     //遍历字符串;
    for(int i = 0;i < n ;i++){
        c=[self characterAtIndex:i];
        //判断是否为数字类型
        if(isdigit(c)){
            //将c转化为int.
            int j = digittoint(c);
            digitString =[digitString stringByAppendingFormat:@"%i",j];
        }
    }
    return digitString ;
}

@end


 类似资料:

相关阅读

相关文章

相关问答