#import <Foundation/Foundation.h>
#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *str=[NSString stringWithFormat:@"zi yi qi"];
NSString *str1=[NSString stringWithFormat:@"ZAI YI QI"];
//比较是否相同
if (str==str1) {
NSLog(@"相等");
}else{
NSLog(@"不等");
}
if ([str isEqualToString:str1]) {
NSLog(@"相等");
}else{NSLog(@"不相等");}
//比较大小
NSComparisonResult st=[str compare:str1];
if (st==NSOrderedAscending) {
NSLog(@"str<str1");
}else if (st==NSOrderedDescending){
NSLog(@"str>str1");
}
else{
NSLog(@"str=str1");
}
//大小写转换
NSString *str3=[NSString stringWithFormat:@"hello hello"];
//转换大写字母
NSLog(@"%@",[str3 uppercaseString]);
//转换成小写字母
NSLog(@"%@",[str3 lowercaseString]);
//把首字母变成大写
NSLog(@"%@",[str3 capitalizedString]);
//创建一个字符常量
// NSString *strr=@"字符串";
//创建一个空的字符串对象
//实例方法
// NSString *strr1=[[NSString alloc]init];
//类方法
// NSString *strr2=[NSString string];
//快速创建一个字符串
// NSString *strr3=[[NSString alloc]initWithCoder:@"字符串"];
// NSLog(@"%@",strr3);
// NSString *strr4=[NSString stringWithString:@"字符窜"];
// NSLog(@"%@",strr4);
//格式化创建字符串
int nums=6;
float num1=7.3;
NSString *strr6=[[NSString alloc]initWithFormat:@"%d",nums];
NSLog(@"%@",strr6);
NSString *strr5=[NSString stringWithFormat:@"%d,%f",nums,num1];
NSLog(@"%@",strr5);
//长度
NSUInteger teg=[str length];
NSLog(@"%ld",teg);
//吧oc的字符串转成c语言的字符串
NSString *str9=@"http://localhost:8099/test/user=admin&pwd=123";
NSLog(@"%@",str9);
const char *str8=[str9 UTF8String];
NSLog(@"%s",str8);
//替换
NSString *str6=[NSString stringWithFormat:@"公司名字:%@,创建时间:%d",@"蓝欧",2011];
NSString *str7=[str6 stringByReplacingOccurrencesOfString:@"蓝欧" withString:@"海鸥"];
NSLog(@"%@",str7);
//拼接
NSString* newstr=[[NSString alloc]initWithFormat:@"拼接后%@ %@",str6,str3 ];
NSLog(@"%@",newstr);
NSString *ster=[str6 stringByAppendingString:str3];
NSLog(@"%@",ster);
//分割
NSString *ster1=[str6 substringFromIndex:3];
NSLog(@"%@",ster1);
NSRange ren=NSMakeRange(2, 5);
NSString *stre2=[str6 substringWithRange:ren];
NSLog(@"%@",stre2);
//
//判断是否有前缀
BOOL rest=[str6 hasPrefix:@"公司名字"];
NSLog(@"%d",rest);
//是否有后缀
BOOL rest1=[str6 hasSuffix:@"2011"];
NSLog(@"%d",rest1);
//查询
NSRange rang=[str6 rangeOfString:@"蓝欧"];
if (rang.location==NSNotFound) {
NSLog(@"未找到");
}else{
NSLog(@"location:%ld length:%ld",rang.location,rang.length);
}
}
return 0;
}