标签:
大小写处理 Upper & Lower case
-(NSString *)uppercaseString -> Alter to upper all
-(NSString *)lowercaseString -> Alter to lower all
-(NSString *)capitalizedString ->Initial upper, rest lower
void caseTest(){
NSString *str=@"GuangDong";
NSLog(@"Uppercase:%@",[str uppercaseString]);
NSLog(@"capitalizestring:%@",[@"age" capitalizedString]);
}
NSString Cmparison 字符串比较 3
-(BOOL)isEqualToString:(NSString *)String ->compare two string content ,if same return YES otherwise return NO
-(NSComparisonResult)compare:(NSString *)strng ->compare two string by each letter,return object NSComparisonResult to show the result.
//NSComparisonResult is a enum with three values
//NSOrderedDescending(left>right),NSOrderedAscending,NSOrderedSame
-(NSComparisonResult)caseInsensitiveCompare:(NSString *)string
//Ignore upper or lower case, return same to compare
//敲这么多英文感觉自己好装B啊,哈哈哈
void compare(){
BOOL result=[@"abc" isEqualToString:@"Abc"];// return NO(YES =1,NO=0)
NSLog(@‘%i‘,result);
NSComparisonResult result2=[@"abc" compare@"ABC"];
if(result2==NSOrderedSame){
NSLog(@"same");
}else if(result2==NSOrderedAscending){
NSLog(@"left<right");
}
else if(result2==NSOrderedDescending){
NSLog(@"left>right");
}
}
//Same lower case letter is larger than upper case of 32
NSString search certain string. NSString 中搜索字符串
-(BOOL)hasPrefix:(NSString *)astring //Whether start with astring
-(BOOL)hasSuffix:(NSString *)astring //Whether end with a string
-(NSRange)rangeOfString:(NSString *)astring
//Check whether include astring ,if include,return the position of astring,if not,return location as -1 of NSRange,length is 0
-(NSRange)rangeOfString:(NSString *)astring options:(NSStringCompareOptions):mask range:(NSString)
void search(){
NSString *str=@"123456456.txt";//only return the first
NSLog(@"Start with 12:%i"[str hasPrefix:@"12"];
NSLog(@"End with txt:%i"[str hasSuffix:@"txt"];
NSRange range=[str rangeOfString:@"345"];
NSLog(@"Include :%@",NSStringFromRange(range)];
if(range.location==NSNNotFound){
NSLog(@"Can‘t find");//range.length==0;
}else{
NSLog(@"%@",NSStringFromRange(range));
}
//Search from back
range=[str rangeOfString:@"456" options:NSBackwardSearch];
NSLog(@"%@",NSStringFromRange(range));
//assign your area of search
range=[str rangeOfString:@"456" options:NSBackwardSearch range];
NSLog(@"%@",NSStringFromRange(range));
}
标签:
原文地址:http://www.cnblogs.com/yesihoang/p/4506117.html