[OC Foundationフレームワーク-6]NSMutablesString
4322 ワード
NSStringは可変ではありません
NSMutablesStringは可変文字列です
1.初期化
2.直列文字列
3.置換文字列
4.文字列の挿入
5.文字列の削除
NSMutablesStringは可変文字列です
1.初期化
2.直列文字列
3.置換文字列
4.文字列の挿入
5.文字列の削除
1 #pragma mark buffer string create
2 void stringCreate()
3 {
4 NSMutableString *mutStr = [[NSMutableString alloc] initWithCapacity:10];
5 [mutStr setString:@"Go!"];
6 NSLog(@"%@", mutStr);
7 [mutStr appendString:@"Hello"];
8 [mutStr appendFormat:@",age is %i and height is %.2f", 12, 1.54];
9 NSLog(@"%@", mutStr);
10
11 //Replace string
12 NSRange r = [mutStr rangeOfString:@"age"];
13 [mutStr replaceCharactersInRange:r withString:@"number"];
14 NSLog(@"%@", mutStr);
15
16 //Insert string
17 [mutStr insertString:@"insert" atIndex:2];
18 NSLog(@"%@", mutStr);
19
20 //Delete string
21 NSRange r2 = [mutStr rangeOfString:@"height"];
22 [mutStr deleteCharactersInRange: r2];
23 NSLog(@"%@", mutStr);
24 }