字符串转int

 

 

#import <Foundation/Foundation.h>

 

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

    @autoreleasepool {

 

        NSString *result1=[[NSString alloc]init];

        NSString *str2=[[NSString alloc]init];

        NSString *str=[[NSString alloc]initWithString:@"158"];

        NSString *str1=[[NSString alloc]initWithString:@"39"];

        int num=[str intValue];

        int num1=[str1 intValue];

        int result=num-num1;

        NSString *strResult1 = [NSString stringWithFormat:@"%d",result];

        

        NSLog(@"  %d ",result);

        

    //  3取出符串“123-456-789-000”中的数字部分,组成一个新的字符串输出

        //NSString *newstr3=[str3 stringByReplacingOccurrencesOfString:@"-" withString:@"" ]; 找到符号  替换成后一个

        NSString *str3=@"123-456-789-000";

        NSString *newstr3=[str3 stringByReplacingOccurrencesOfString:@"-" withString:@"" ];

        NSLog(@"%@",newstr3);

    //4放四个十进制三位数到一个数组中,然后按从小到大排序后组成一个新的数组

        NSArray *arr=@[@"3",@"2",@"1"];

        

        NSArray *arrNew=[arr sortedArrayUsingSelector:@selector(compare:)];

        

        NSLog(@"%@",arrNew);      

    }

    return 0;

}

 

posted @ 2016-01-11 09:40  流浪法师0  阅读(976)  评论(0编辑  收藏  举报