首页 > 其他 > 详细

练习题1

时间:2016-01-11 13:54:47      阅读:218      评论:0      收藏:0      [点我收藏+]
//
//  1.整数123456789,如何将这个整数的每一位数,从末位开始依次放入一个数组中,并将他们遍历出来
//  2.如何将字符串@“abc123.xyz789”倒置
//  3.将2013年05月05日转换成2013-05-05

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog(@"第一题");
        NSInteger num=123456789;
        //NSNumber *newnum=@(num);
        NSString *strnum=[[NSString alloc]initWithFormat:@"%ld",num];
        NSMutableArray *arr=[NSMutableArray array];
        for (int i=8; i>=0; i--) {
            NSRange range;
            range.length=1;
            range.location=i;
            NSString *str=[NSString alloc];
            str=[strnum substringWithRange:range];
            [arr addObject:str];
        }
        for (id str1 in arr) {
            NSLog(@"%@",str1);
        }
        NSLog(@"第二题");
        NSString *string=@"abc123.xyz789";
        NSMutableString *newString=[[NSMutableString alloc]initWithCapacity:string.length];
        for (long i=string.length-1; i>=0; i--) {
            [newString appendFormat:@"%c",[string characterAtIndex:i]];
        }
        NSLog(@"%@",newString);
        NSLog(@"第三题");
        NSString *date=@"2013年05月05日";
        NSMutableString *Date=[NSMutableString stringWithString:date];
        NSRange rangeDate;
        int i=4;
        while (i<9) {
            rangeDate.length=1;
            rangeDate.location=i;
            [Date replaceCharactersInRange:rangeDate withString:@"-"];
            i+=3;
        }
        NSString *newdate=[Date substringToIndex:i];
        NSLog(@"%@",newdate);
    }
    return 0;
}

 

练习题1

原文:http://www.cnblogs.com/haitong-0311/p/5120864.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!