IOS NSString 操作
1>初始化:
stringWithContentsOfFile:
stringWithContentsOfURL:
stringByAppendingString:
initWithString:
stringWithString:
stringWithFormat:
writeToFile:
stringWithContentsOfFile:
2>比较:isEqualToString,compare,NSComparisonResult
BOOL result = [astring01 isEqualToString:astring02]
compare方法(comparer返回的三种值:NSOrderedSame,NSOrderedAscending,NSOrderedDescending)
NSString *astring01 = @"This is a String!"
caseInsensitiveCompare 不区分大小写
[astring01 compare:astring02 options:NSCaseInsensitiveSearch | NSNumericSearch]
//NSCaseInsensitiveSearch:不区分大小写比较, NSLiteralSearch:进行完全比较,区分大小写, NSNumericSearch:比较字符串的字符个数,而不是字符值。
NSComparisonResult result=[self.birthDate compare:another.birthDate];
if(result==NSOrderdSame) return 0;
if(result==NSOrderdAscending) return -1;
else return 1;
3>截取:
rangeOfString:
substringToIndex:3
substringFromIndex:
substringWithRange:
hasPrefix:
hassuffix: