最简单的创建方法
NSString *str=[NSString alloc]initWithString:@"lxd"];
把int型 格式化成字符串
int i=9;
NSString *str=[NSString alloc]initWithFormat:@"%d",i];
静态方法创建字符串
NSString *str=[NSString stringWithFormat:@"%@",@"lxd"];
拼接字符串
NSString *str3=[NSString stringWithFormat:@"%@",@"ab"];
NSString *str4=[str3 stringByAppendingFormat:@"bc"];
NSLog(@"%@",str4);
//节 字符串
NSString *str5=[NSString stringWithFormat:@"%@",@"abcdef"];
NSString *str6=[str5 substringFromIndex:1];
NSRange r={2,3};
NSString *str7=[str6 substringWithRange:r];
//查找字符串
NSRange r1=[str5 rangeOfString:@"b"];
//把字符串 强转为 整形(INT) 关键:intValue
NSString *str9=[NSString stringWithFormat:@"%@",@"12"];
int a = [str9 intValue];
NSLog(@"a=%d",a);
//字符串的比较
NSString *str10=@"a1";
NSString *str11=@"a2";
NSComparisonResult rest= [str10 compare:str11];
NSLog(@"%d",rest);
//转换大小写 lowercaseString:小写 uppercaseString :大写
NSString *str12=@"abc2";
NSString *str13=[str12 uppercaseString];
NSLog(@"%@",str13);
//可变字符串 initWithCapacity 分配内存因子
// NSMutableString *mutableStr1=[[NSMutableString alloc]initWithCapacity:12];
NSMutableString *mutableStr1=[NSMutableString stringWithCapacity:12];
[mutableStr1 appendString:@"s"];//添加字符串
// [mutableStr1 appendFormat:@"a"];//添加字符串 两种都可以 添加
[mutableStr1 appendFormat:@"%d",26];
NSRange r2={1,2};
[mutableStr1 deleteCharactersInRange:r2];//删除字符串
NSLog(@"length=%d",mutableStr1.length);
// [mutableStr1 release];