#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//nsstring父类 NSMutableString可变字符串子类
NSMutableString *mustr=[[NSMutableString alloc]init];
NSMutableString *mustr1=[NSMutableString stringWithFormat:@"Hello"];
//将不可变的字符串放置到可变字符串内
NSString *str=@"welcome to oc";
mustr=[NSMutableString stringWithString:str];
//插入
[mustr insertString:@" students " atIndex:7];
[mustr appendString:@" teacher"];
[mustr appendFormat:@"第二遍插入:%@",str];
//删除
[mustr deleteCharactersInRange:NSMakeRange(8, 10)];
//查找并删除
NSRange rang=[mustr rangeOfString:@"第二遍插入:welcome to oc"];
if (rang.location!=NSNotFound) {
[mustr deleteCharactersInRange:rang];
}
//重新赋值
[mustr setString:str];
//替换
NSRange rang1=[mustr rangeOfString:@"oc"];
[mustr replaceCharactersInRange:rang1 withString:@"IOS"];
NSLog(@"%@",mustr);
//判断字符串是否有此前缀
NSString *str=@"IOS8-赵玉鑫.jpg";
BOOL result = [str hasPrefix:@"IOS"];
NSLog(@"%d",result);
//判断字符串是否有此后缀
BOOL resultsu = [str hasSuffix:@".jpg"];
NSLog(@"%d",resultsu);
长度
//1.定义字符串对象
NSString *str=[NSString stringWithString:@"zi fu chuan"];
//2.计算字符串长度
NSUInteger len = [str length];
//3.输出字符串长度
NSLog(@"zi fu chuan的长度是%ld",len);
}
return 0;
}