*创建
NSString *str1 = @"Hello World!";
NSString *str2 = [[NSString alloc]initWithCString:"Hello World!" encoding:NSUTF8StringEncoding];
NSString *str3 = [NSString stringWithCString:"Hello World!" encoding:NSUTF8StringEncoding];
NSString *str4= @"Hello World!";
*常用数值比较
NSString *astring01 = @"This is a String!";
NSString *astring02 = @"This is a String!";
BOOL result = [astring01 isEqualToString:astring02];
NSLog(@"result:%d",result);
*伪更改:返回新字符串
str1=[str1 stringByAppendingString:@" Yes!"];
NSRange stringRange = NSMakeRange(12, 4);
str1=[str1 stringByReplacingCharactersInRange:stringRange withString:@"Good"];
NSLog(@"after change... str1=%@",str1);
NSLog(@"str1:%p",str1);
*NSMutableString的可变性
NSMutableString *mustr1 = [NSMutableString stringWithString: @"Hello,World!"];
NSLog(@"mustr1:%p",mustr1);
NSMutableString *mustr2 = [NSMutableString stringWithString: @"Hello,World!"];
NSLog(@"mustr2:%p",mustr2);
NSString *str5=mustr1;
NSLog(@"str5:%@",str5);
[mustr1 appendString:@" Very Good!"];
NSLog(@"str5:%@",str5);
*NSMutableString的增删改查方法
NSMutableString *mustr3 =[NSMutableString stringWithCapacity:100];
[mustr3 appendString:@"Hello Objective"];
[mustr3 insertString:@"-C" atIndex:mustr3.length];
[mustr3 setString:@"Hi Objective"];
NSRange replaceRange = NSMakeRange(0, 2);
[mustr3 replaceCharactersInRange:replaceRange withString:@"Hello"];
NSRange deleteRange = NSMakeRange(5, 10);
[mustr3 deleteCharactersInRange:deleteRange];