1.截取字符串
NSString*string =@"sdfsfsfsAdfsdf";string = [string substringToIndex:7];//截取下标7之后的字符串NSLog(@"截取的值为:%@",string);[string substringFromIndex:2];//截取下标2之前的字符串NSLog(@"截取的值为:%@",string);2.匹配字符串
NSString*string =@"sdfsfsfsAdfsdf";NSRangerange = [stringrangeOfString:@"f"];//匹配得到的下标NSLog(@"rang:%@",NSStringFromRange(range));string = [string substringWithRange:range];//截取范围类的字符串NSLog(@"截取的值为:%@",string);3.分隔字符串NSString*string =@"sdfsfsfsAdfsdf";NSArray *array = [string componentsSeparatedByString:@"A"]; //从字符A中分隔成2个元素的数组NSLog(@"array:%@",array); //结果是adfsfsfs和dfsdf
小写字符转为大写字符
1 NSString *str = @"mobile developer tips";
2
3 // Convert string to uppercase
4 NSString *upperStr = [str uppercaseStringWithLocale:[NSLocale currentLocale]];
5 NSLog(@"upperStr: %@", upperStr);
6
7 // Convert string to caps
8 NSString *capStr = [upperStr capitalizedStringWithLocale:[NSLocale currentLocale]];
9 NSLog(@"capStr: %@", capStr);
10
11 // Convert string to lowercase
12 NSString *lowerStr = [capStr lowercaseStringWithLocale:[NSLocale currentLocale]];
13 NSLog(@"lowerStr: %@", lowerStr);