#pragma mark -字符串的比较
void text() {
NSString * str = @"RongTian";
// 转成大写
[str uppercaseString];
// 转成小写
[str lowercaseString];
// 首字母大写,其余小写
[@"ffEW" capitalizedString];
}
#pragma mark 比较2个字符串的大小
void compareString() {
// NSOrderedAscending -1
// NSOrderedSame
// NSOrderedDescending
NSComparisonResult result = [@"bmn" compare:@"azz"];
if (result == NSOrderedSame) {
NSLog(@"左 == 右");
}else if (result == NSOrderedDescending) {
NSLog(@"左 > 右");
}else if (result == NSOrderedAscending)
{
NSLog(@"左 <</span> 右");
}
NSComparisonResult caseInsenresult = [@"dffA" caseInsensitiveCompare:@"dffa"];
if (caseInsenresult == NSOrderedSame) {
NSLog(@"左 == 右");
}else if (caseInsenresult == NSOrderedDescending) {
NSLog(@"左 > 右");
}else if (caseInsenresult == NSOrderedAscending)
{
NSLog(@"左 <</span> 右");
}
}
#pragma mark 字符串的搜索
void searchString() {
NSString *str = @"456789456";
NSLog(@"是否456开头 %i", [str hasPrefix:@"456"]);
NSLog(@"是否789结尾 %i",[str hasSuffix:@"789"]);
NSRange range = [str rangeOfString:@"567"];
if (range.location == NSNotFound) {
NSLog(@"str中没有找到 567");
}else {
NSLog(@"搜索范围 %@",NSStringFromRange(range));
}
// 或者
// if (range.length == 0 ) {
// NSLog(@"str中没有找到 567");
// }
// 从尾开始搜索
range = [str rangeOfString:@"456" options:NSBackwardsSearch] ;
NSLog(@"从尾搜索的范围 %@",NSStringFromRange(range));
// [str rangeOfString: