NSString *str = @"hello word!";
NSString *str1 = [[NSString alloc] initWithString:str];
NSString *str2 = [[NSString alloc] initWithUTF8String:"hello world!"];
NSString *str2 = [[NSString alloc] initWithFormat:"hello %d %c",37,'Z'];
不需要手动释放
字符串比较:
NSString *str1=@"1";
NSString *str2=@"2";
NSComparisonResult ret = [str1 compare:str2];
if(ret == NSOrderedAscending){
NSLog(@"str1<str2");
}else if(ret == NSOreredSame){
NSLog(@"str1==str2");
}else if(ret == NSOrderedDescending){
NSLog(@"str1>str2");
}