Objective-C字符串NSString与NSMutableString

1.C风格和OC风格字符串的转换      stringWithUTF8String/UTF8String

Objective-C字符串NSString与NSMutableString_第1张图片


2.NSString字符串的声明 

Objective-C字符串NSString与NSMutableString_第2张图片


3.字符串格式化      stringWithFormat



4.NSString字符串的拼接      stringByAppendingString

Objective-C字符串NSString与NSMutableString_第3张图片


5.字母大小写转换     lowercaseString/uppercaseString

Objective-C字符串NSString与NSMutableString_第4张图片


6.判断字符串是否包含前缀/后缀      hasPrefix/hasSuffix

Objective-C字符串NSString与NSMutableString_第5张图片


7.字符串相同的判断    isEqualToString

Objective-C字符串NSString与NSMutableString_第6张图片


8.字符串的分割    componentsSeparatedByString

Objective-C字符串NSString与NSMutableString_第7张图片


9.字符串的截取     substringWithRange/substringFromIndex/substringToIndex

Objective-C字符串NSString与NSMutableString_第8张图片


10.字符串中查找指定字符串内容(获得NSRange对象)    rangeOfString    



11.字符串的替代      stringByReplacingCharactersInRange/stringByReplacingOccurrencesOfString

Objective-C字符串NSString与NSMutableString_第9张图片


12.URL路径和本地文件路径的转换    URLWithString/fileURLWithPath

Objective-C字符串NSString与NSMutableString_第10张图片


13.NSMutableString可变字符串(NSMutableString是NSString的子类)

13-1 NSMutableString的初始化:

NSMutableString *str = [[NSMutableString alloc]  init];//初始化

NSMutableString *str_1 = [[NSMutableString alloc] initWithCapacity: 12];//初始化得到长度为12的可变字符串

[str setString:@"Hello"];//赋值


13-2 替换字符串

NSRange range = [str rangeOfString:@"Hello"];

[str replaceCharactersInRange:range withString:@"Hi"];


13-3插入字符串

[str insertString:@"IOS" atIndex:2];


13-4 删除字符串

NSRange range = [str rangeOfString:@"IOS"];

[str deleteCharactersInRange:range];


13-5 追加字符串

[str appendString:@"IOS"];

[str appendFormat:@"%d", 200];

你可能感兴趣的:(Objective-C字符串NSString与NSMutableString)