NSString [a hasPrefix: ] [a hasSuffix:] 判断开头和结束是否包含....
- (void)viewDidLoad
{
NSMutableString *a = [[NSMutableString alloc ] initWithString :@"i like long dress"];
NSLog(@"\n a: %@",a);
[a hasPrefix:@"i"] ==YES? NSLog(@"以 i 开头"): NSLog(@"不以 i 开头");
[a hasSuffix:@"hat"] ==YES? NSLog(@"以 hat 结尾"): NSLog(@"不以 hat 结尾");
[a release];
}
2011-07-11 18:42:55.734 Q[6700:207] a: i like long dress
2011-07-11 18:42:55.736 Q[6700:207] 以 i 开头
2011-07-11 18:42:55.737 Q[6700:207] 不以 hat 结尾
查找 字符串 是否包含 某东东时还可以用 rangeOfString