12月23号 Foundation库NSString操作
2015-12-23 13:39
239 查看
NSString(不可变字符串 创建之后就不能增删改)
1.创建字符串
//1.静态 alloc new copy mutablecopy
NSString *str = @"王浩宇:签了三方的同学,请尽快到学校网站填写相关信息,步骤已发到12级群共享";
//2.alloc 空字符串对象
NSString *str2 = [[[NSString alloc] init] autorelease];
//3.alloc 有初始值的字符串对象
NSString *str3 = [[[NSString alloc] initWithString:str] autorelease];
//不要自己控制内存 工厂方法 便利器方法
NSString *str31 = [NSString stringWithString:str];
NSLog(@"%@", str31);
//4.字符串按照一定的格式拼接 age = 20 height = 170
NSString *str4 = [[[NSString alloc] initWithFormat:@"age=%d height=%d", age, height] autorelease];
NSString *str4 = [NSString stringWithFormat:@"age=%d height=%d", age, height];
NSLog(@"%@", str4);
2.length 获取字符串长度
3.获取子字符串
1) substringFromIndex:
2)substringToIndex:
3) substringWithRange:
typedef struct _NSRange {
NSUInteger location;
NSUInteger length;
} NSRange;
4.字符串的比较
a. isEqualToString:
b. compare:
typedef enum {
NSOrderedAscending,//a < b
NSOrderedSame,//a = b
NSOrderedDescending//a > b
}NSComparisonResult;
1)比较两个字符串是否相同
2)比较两个字符串的大小
5.字符串的查找
6.类型转化
a. intValue
b. boolValue
c. floatValue
d. doubleValue
1.创建字符串
//1.静态 alloc new copy mutablecopy
NSString *str = @"王浩宇:签了三方的同学,请尽快到学校网站填写相关信息,步骤已发到12级群共享";
//2.alloc 空字符串对象
NSString *str2 = [[[NSString alloc] init] autorelease];
//3.alloc 有初始值的字符串对象
NSString *str3 = [[[NSString alloc] initWithString:str] autorelease];
//不要自己控制内存 工厂方法 便利器方法
NSString *str31 = [NSString stringWithString:str];
NSLog(@"%@", str31);
//4.字符串按照一定的格式拼接 age = 20 height = 170
NSString *str4 = [[[NSString alloc] initWithFormat:@"age=%d height=%d", age, height] autorelease];
NSString *str4 = [NSString stringWithFormat:@"age=%d height=%d", age, height];
NSLog(@"%@", str4);
2.length 获取字符串长度
3.获取子字符串
1) substringFromIndex:
2)substringToIndex:
3) substringWithRange:
typedef struct _NSRange {
NSUInteger location;
NSUInteger length;
} NSRange;
4.字符串的比较
a. isEqualToString:
b. compare:
typedef enum {
NSOrderedAscending,//a < b
NSOrderedSame,//a = b
NSOrderedDescending//a > b
}NSComparisonResult;
1)比较两个字符串是否相同
2)比较两个字符串的大小
5.字符串的查找
6.类型转化
a. intValue
b. boolValue
c. floatValue
d. doubleValue
相关文章推荐
- hdu 畅通工程
- 【编译原理】:编译原理各种文法对应的自动机
- 杀不死的Service
- Javascript的IE和Firefox兼容性
- pthread属性设置
- php中的$this和self
- grunt中遇到一个一直运行一个任务的问题
- 关于stl string find 容易犯的一个错误
- 安卓技术积累(1)
- java多文件打包下载
- 便于使用VS2010的C#第一个程序
- Loaders 的使用,结合Fragments
- LA 4094 WonderTeam 构造
- 从Eclipse+ADT迁移到Android Studio
- Android 应用程序常用工具类及功能包
- 可以在 Linux 下试试苹果编程语言 Swift
- 安卓开发笔记(二)------------终止一个线程
- Android中多线程下载列表的封装实现(含进度反馈)
- MaterialDesign 之 NavigationView
- bitnami 版 gitlab 修改端口