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