3、字符串的替換
注:將字符串中的參數進行替換
參數1:目標替換值
參數2:替換成爲的值
參數3:類型爲默認:NSLiteralSearch
參數4:替換的範圍
[str replaceOccurrencesOfString:@"1" withString:@"222" options:NSLiteralSearch range:NSMakeRange(0, [str length])];
5、追加字符串
NSMutableString *String1 = [[NSMutableString alloc] initWithString:@"This is a NSMutableString"];
[String1 appendFormat:[NSString stringWithFormat:@", I will be adding some character"]];[String1 hasSuffix:@".txt"] = = 1 ? NSLog(@"YES") : NSLog(@"NO");
10、返回一個數組,包含從已經由一個給定的分隔符分爲接收器串。
- (NSArray*)componentsSeparatedByString:(NSString*)NString
參數
分離器
分隔符的字符串。
NSString *list = @"Norman, Stanley, Fletcher";
NSArray *listItems =
[list componentsSeparatedByString:@", "];
listItems包含了:
{ @"Norman", @"Stanley", @"Fletcher" }.
11、是否包含該字符串
NSRange range = [@"字符串--A" rangeOfString:“是否包含--B”];
if (range.location == NSNotFound)
{//不包含
}
else
{//包含
}