标签:
// 求字符串"158"和"39"按十进制数值做差后的结果以字符串形式输出
NSString *str1 = @"158";
NSString *str2 = @"39";
int a = [str1 intValue];
int b = [str2 intValue];
int c = a - b;
NSString *res = [NSString stringWithFormat:@"%d", c];
NSLog(@"%@", res);
// 取出字符串"123-456-789-000"中数字部分,组成一个新的字符串输出
NSString *string = @"123-456-789-000";
NSArray *array = [string componentsSeparatedByString:@"-"];
NSString *result = [array componentsJoinedByString:@""];
NSLog(@"%@", result);
// 有一个数组 @[@"kick", @"off", @10] 将数组中@10去掉
NSArray *arr5 = @[@"kick", @"off", @10];
NSMutableString *new = [NSMutableString string];
for (NSString *obj in arr5){
if (![obj isKindOfClass:[NSNumber class]]){
[new appendString:obj];
}
}
NSLog(@"%@", new);
// 将2013年05月05日转换为 2013-05-05
NSString *time = @"2013/05/05";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd";
NSDate *date = [formatter dateFromString:time];
NSLog(@"%@", date);
标签:
原文地址:http://www.cnblogs.com/lianfu/p/5159071.html