iOS学习笔记(一)---NSMutableString可变数组
来源:互联网 发布:南京大汉网络做什么 编辑:程序博客网 时间:2024/06/07 22:19
其余NSString的区别:
1、是一个可变的字符串
2、可以添加、删除、替换字符串
3、继承了NSString
@interface NSMutableString : NSString
基本操作
基本方法包括:初始化
- (NSMutableString *)initWithCapacity:(NSUInteger)capacity;+ (NSMutableString *)stringWithCapacity:(NSUInteger)capacity;//静态方法,推荐使用:不用考虑释放内存插入
- (void)insertString:(NSString *)aString atIndex:(NSUInteger)loc;
删除
- (void)deleteCharactersInRange:(NSRange)range;添加
- (void)appendString:(NSString *)aString;- (void)appendFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2);
替换
- (void)setString:(NSString *)aString;
具体使用示例:
//1、初始化 NSMutableString *str = [NSMutableString stringWithCapacity:20]; //2、添加 [str appendString:@"Hello"]; [str appendString:@" World!"]; NSLog(@"%@",str); //3、删除字符 NSRange r = NSMakeRange(3, 3); [str deleteCharactersInRange:r]; NSLog(@"%@",str); //4、插入字符 NSString *str1 = @"Gugu"; NSMutableString *str2 = [NSMutableString stringWithFormat:@"hello "]; [str2 insertString:str1 atIndex:6]; NSLog(@"%@",str2); //5、替换 [str2 setString:@"hello world!"]; NSLog(@"%@",str2);运行结果:
2016-02-19 20:02:57.340 Objective-C[18778:1131913] Hello World!2016-02-19 20:02:57.341 Objective-C[18778:1131913] HelWorld!2016-02-19 20:02:57.341 Objective-C[18778:1131913] hello Gugu2016-02-19 20:02:57.341 Objective-C[18778:1131913] hello world!Program ended with exit code: 0
0 0
- iOS学习笔记(一)---NSMutableString可变数组
- IOS NSMutableString(可变字符串)
- IOS NSMutableString可变字符串
- Objective-C学习笔记(二)------NSString和NSMutableString类
- IOS学习笔记-UITableView (一)
- iOS objective-c之-8:数组NSArray 可变数组-(NSMutableArray)
- IOS NSString NSMutableString 不可变|可变字符串
- ios Foundation框架中的可变和不可变对象NSString 和NSMutableString(一)
- NSString NSMutableString (学习笔记二)
- ios学习第二天(一)对象之字符串NSString和NSMutableString
- React Native 学习笔记-iOS(一)
- iOS-RAC学习笔记(一)——RACStream
- iOS objective-c之-8:数组NSArray 可变数组-NSMutableArray
- 黑马程序员-ios学习笔记 c语言 数组
- Object-C 可变字符串(NSMutableString)
- 数组学习笔记(一)
- OC学习笔记之NSMutableString
- IOS学习笔记(一)
- TOEFL 学习笔记(writing 4)
- JFrame的组成结构
- rac初识之冷热信号
- 如何用剪切板实现数据传递(本文分字符串和对象)
- POJ 1523 SPF(Tarjan 求解连通分量)
- iOS学习笔记(一)---NSMutableString可变数组
- MySQL中一致性非锁定读
- 说说我对spark-sql的job的参数调优
- Toast源代码分析
- Linux CentOS系统启动时遇到的报错
- Innodb中的事务隔离级别和锁的关系
- EditText属性详解
- Math.round(11.5)等于多少?Math.round(-11.5)等于多少?
- 冒泡排序Bubble Sort