标签:
一 字符串
二 可变字符串的初始化方法
对象方法的初始化
//init是对象方法
//将不可变字符串转换为可变字符串
NSMutableString *str2=[[NSMutableString alloc] initWithString:str1];
NSLog(@"%ld",str2.length);
// [str2 insertString:@"lll" atIndex:3];
// NSLog(@"%@",str2);
//拼接字符串,插入最后前,字符串长度自然多加后面字符串长度 与C语言不同长度数组越界 拼接之前 atIndex后面就是 0
[str2 insertString:@"and lisi" atIndex:str2.length];
NSLog(@"%@",str2);
//在后面拼接
[str2 appendString:@"and lisi"];
//从0开始删除3个字符
[str2 deleteCharactersInRange:NSMakeRange(6, 5)];
//替换字符串替换范围内的字符串
[str2 replaceCharactersInRange:NSMakeRange(6, 5) withString:@"wang"];
//替换所有的字符的字符串
[str2 replaceOccurrencesOfString:@"a" withString:@"p" options:NSCaseInsensitiveSearch range:NSMakeRange(0, str2.length)];
//将C语言字符串转为可变字符串
char *name="zhangsan";
NSMutableString *str3=[[NSMutableString alloc] initWithUTF8String:name];
NSLog(@"%ld",str3.length);
//通过格式化来初始化可变字符串
NSMutableString *str4=[[NSMutableString alloc] initWithFormat:@"hell%d",123];
NSLog(@"%ld",str4.length);
//通过字符串的长度来初始化字符串 0
NSMutableString *str5=[[NSMutableString alloc] initWithCapacity:10];
//直接初始化 0
NSMutableString *str6=[[NSMutableString alloc] init];
[str6 insertString:@"lisi" atIndex:0];
//stringwith是类方法
NSMutableString *str7=[NSMutableString stringWithUTF8String:name];
NSMutableString *str8=[NSMutableString stringWithFormat:@"hell%d",123];
NSMutableString *str9=[NSMutableString string];
NSMutableString *str10=[NSMutableString stringWithString:@"lisi"];
类方法的初始化
三
标签:
原文地址:http://www.cnblogs.com/gzoof/p/5434060.html