Foundation——字符串
来源:互联网 发布:mac中文字体下载 编辑:程序博客网 时间:2024/04/30 00:01
字符串
一、不可变字符串的创建的几种方法
1、字符串的创建
NSString *str1 = @“i love panda”;NSString *str2 = [NSString StringWithFormate:@“i am %d”, 10];//将字符串转为数字。 NSStirng *str3 = [NSString alloc] initWithFormate:@“i am %d”, 10];
2、将c语言字符串,转成OC字符串,参数字符串无序加@,因为是c语言字符串
NSString *str4 = [[NSString alloc] initWithUTFString:“i love Panda”];
3、将OC语言字符串转成c语言字符串
const char *c = [str UTF8String];memcpy(字符数组, [strUTF8String], length);转为字符数组
4、传文件绝对路径,从文件中取出字符串NSUTF8StringEncoding
NSString *str5 = [[NSString alloc] initWithContentOFFile:@“/文件绝对路径” encoding:NSUTF8StringEncoding error:nil];
5、资源路径URL
//协议头://路径 //file://路径 本地资源 //ftp://路径 ftp服务器资源 //http://weibo.com/a.png 网络资源
6、写内容到文件
[@“wirte to \n file” wirteToFile:@“/apple/a.txt” automically:YES encoding:NSUTF8StringEncoding error:nil]; [@“wirte to \n URL” wirteToURL:资源路径 automically:YES encoding:NSUTF8StringEncoding error:nil];
二、NSMutableString可变字符串
它是NSString的子类,所以以上方法NSMutalbeString都能用
1、字符串的拼接,下面的代码会自动发字符串的内容拼接到可辨字符串的后面,前提是str是可变字符串
[str appendString:@“i love panda”];
2、删除某一范围内的内容
NSRange r = [str RangeOfString:@“love”];//搜索字符串 [str deleteCharactersInRange:r]; substringWithRange//截取某一范围字符串
3、replace某个范围内的所有字符串,有两个方法
replaceCharactersInRange:NSRange withString:@""//把这个范围内的字符串,无论多长,替换成后面的字符串。 [strreplaceOccurrencesOfString:@"do"withString:@"fuck"options:NSCaseInsensitiveSearchrange:rang2];//把某一范围内重复的字符串替换掉
4、 把两个字符串拼接返回一个新的字符串
NSString *str = [s1 StringByAppendingString:@“i am"];
0 0
- Foundation——字符串
- Foundation——字符串
- Foundation——字符串
- Foundation框架—字符串
- Foundation框架—字符串
- Foundation框架—字符串
- Foundation框架—字符串
- Foundation框架—字符串
- Objective-C Foundation——字符串
- IOS学习之Foundation框架—字符串
- Foundation框架—字符串NSString 和 NSMutableString
- 黑马程序员——Foundation框架—字符串方法
- 黑马程序员——Foundation框架:字符串之集合类
- 黑马程序员——Foundation框架结构体、字符串、数组
- ObjectC语言基础2—Foundation、结构体、字符串、集合
- Foundation框架(2)——读取文件中的字符串、把字符串写入文件中
- Foundation——集合
- Foundation——NSSet
- mysql夸库复制表命令
- 调用系统的图库和系统相机完成获取头像功能 包括popupWindow的使用
- 第十一周项目1——二叉树算法验证(3)
- 导出到excel表格
- 经典漫画讲解HDFS原理
- Foundation——字符串
- Foundation——集合类
- Foundation——结构体
- 华为OJ题目(四):字符逆序
- (转)java判断string变量是否是数字的六种方法小结
- 第十一周--项目2用二叉树求解代数表达式
- 如何高效检查一个数组中是否包含某个值
- Linux性能评测工具之一:gprof篇
- android 9path教程与去黑边