1.NSString常用方法
a.字符串拼接:stringWithFormat
int age=18;
NSString *_name=@"小明";
NSString *_content =[NSString stringWithFormat:@"我叫%@,我今年%d岁了",_name,age];
NSLog(_content);
b.获取字符串长度
NSString *str=@"搜索12jj";
int length=[str length];
NSLog(@"%d",length);
c.获取字符串指定下表的字符
NSString *str= @"中国我爱你";
unichar ch=[str characterAtIndex:2];
NSString *s=[NSString stringWithFormat:@"ch=%C",ch];
NSLog(s);
d.判断两个字符串的内容是否相同
NSString *str1=@"小明";
NSString *str2=[NSString stringWithFormat:@"小明"];
if([str1 isEqualToString:str2]){
NSLog(@"相等");
}else{
NSLog(@"不相等");
}
e.字符串比较大小
NSString *str1=@"china";
NSString *str2=@"japan";
int value=[str1 compare:str2];
NSLog(@"value=%d",value);