NSMutableString的几个常用接口
来源:互联网 发布:淘宝自由搭配套餐 功能 编辑:程序博客网 时间:2024/05/16 06:22
不同于固定字符串类型NSString,NSMutableString的可修改属性,适应性更好。
NSMutableString继承自NSString,因此有的接口,比如初始化接口可以使用NSString的格式。另外,
NSMutableString的其他常用接口还有:
- (void)appendString:(NSString *)aString
- (void)appendFormat:(NSString *)
format
, ...
- (void)deleteCharactersInRange:(NSRange)
aRange
- (void)insertString:(NSString *)
aString
atIndex:(NSUInteger)anIndex
- (void)replaceCharactersInRange:(NSRange)
aRange
withString:(NSString *)aString
- (void)setString:(NSString *)
aString
举例如下:
NSString *str1 = @"hello world."; NSMutableString *str2 = [[NSMutableString alloc] initWithString:str1]; NSMutableString *str3 = [NSMutableString stringWithString:str1]; NSMutableString *str4 = [[NSMutableString alloc] initWithFormat:@"he%@ wor%cd.",@"llo",'l']; NSMutableString *str5 = [NSMutableString stringWithFormat:@"he%@ wor%cd.",@"llo",'l']; NSLog(@"str2 is %@", str2); NSLog(@"str3 is %@", str3); NSLog(@"str4 is %@", str4); NSLog(@"str5 is %@", str5); [str2 setString: @"str2 is a mutable string."]; NSLog(@"str2 is %@", str2); [str3 appendString:@"str3 is a mutable string."]; NSLog(@"str3 is %@", str3); [str4 appendFormat:@"str4 is a %@", @"mutable string."]; NSLog(@"str4 is %@", str4); [str5 insertString:@"###" atIndex:7]; NSLog(@"str5 is %@", str5); [str5 deleteCharactersInRange:NSMakeRange(2, 3)]; NSLog(@"str5 is %@", str5); [str5 replaceCharactersInRange:NSMakeRange(6, 2) withString: @"****"]; NSLog(@"str5 is %@", str5);
输出结果:
2015-11-02 22:35:36.233 testNSMutableString[549:16998] str2 is hello world.2015-11-02 22:35:36.233 testNSMutableString[549:16998] str3 is hello world.2015-11-02 22:35:36.234 testNSMutableString[549:16998] str4 is hello world.2015-11-02 22:35:36.234 testNSMutableString[549:16998] str5 is hello world.2015-11-02 22:35:36.234 testNSMutableString[549:16998] str2 is str2 is a mutable string.2015-11-02 22:35:36.234 testNSMutableString[549:16998] str3 is hello world.str3 is a mutable string.2015-11-02 22:35:36.234 testNSMutableString[549:16998] str4 is hello world.str4 is a mutable string.2015-11-02 22:35:36.234 testNSMutableString[549:16998] str5 is hello w###orld.2015-11-02 22:35:36.234 testNSMutableString[549:16998] str5 is he w###orld.2015-11-02 22:35:36.234 testNSMutableString[549:16998] str5 is he w##****rld.
0 0
- NSMutableString的几个常用接口
- NSMutableString常用的函数
- 几个常用的小接口
- NSString的几个常用接口
- NSMutableString的常用基础操作
- Servlet几个常用的Listener接口
- Spring启动常用的几个接口
- spring常用的几个aware bean接口:
- 常用的NSString和NSMutableString方法
- 常用的NSString和NSMutableString方法
- 常用的NSString和NSMutableString方法
- 常用的NSSring和NSMutableString方法
- NSString与NSMutableString的常用操作
- 常用的NSString和NSMutableString方法
- iOS NSString,NSMutableString的常用用法
- Objective-C 6 NSMutableString的常用方法
- NSString 与NSMutableString的常用方法
- 几个常用的url生成二维码的接口
- 链表实现动态内存管理
- VMware虚拟机配置Ubuntu桥接方式(Bridged)使虚拟机和宿主机能互相ping通
- 浅谈java与.Net的相互调用
- linux fork.c
- 2013-专利电子收集
- NSMutableString的几个常用接口
- Java动态规划 实现最长公共子序列以及最长公共子字符串
- iOS UINavigation
- 对建立和删除索引的认识
- 基于MFC对话框编程:设置开机自启动
- Java动态规划 实现最长公共子序列以及最长公共子字符串
- 2014-08-22-小絮“中兴跑酷”
- 行为型模式之五——备忘录模式
- 谈谈:如何避免新入职的程序员痛苦和迷茫?