字符串的表示
字符串使用NSString,用@”"来表示字符串。
NSString是只读的字符串。
NSString *string = @"Hello World!";
可修改的字符串要这样声明:
NSMutableString * string = [NSMutableString stringWithString:@"Hello World!"];
字符串操作
// 与字符串连接
NSMutableString * string = [NSMutableString stringWithString:@"aaa"];
NSString *joined = [string appendString:@"bbb"];
//字符串追加 NSMutableString *str=[[NSMutableStringalloc] initWithString:@"dd"]; str=[str stringByAppendingString:@"eee" ];
//字符串替换
NSString *str = @"Hello world!";
str =[str stringByReplacingOccurrencesOfString:"world" withString:"China"];
字典的操作
・获得Key
NSArray *keys = [dictionary allkeys]・获得值
NSArray *values = [dictionary allValues];・删除Key(NSMutableDictionary的实例)
[dictionary removeObjectForKey:@"key1"];