Objective-C学习笔记-NSString
来源:互联网 发布:java 当前时间转整型 编辑:程序博客网 时间:2024/06/05 15:51
OC的不可变字符串
OC 字符串的创建方式
- 直接赋值
NSString *str=@"hello world";//oc的字符串必须加上@符号
- 手动实例化
NSString *str=[[NSString alloc] init]; str=@"hello ios";
字符串的常用操作
- c字符串和oc字符串的互相转化
char *cStr="I am c";//c语言字符串 NSString *nsStr=[NSString stringWithUTF8String:cStr]//转换成oc NSString *str=@"I am oc";//oc字符串 char *c=[str UTF8String];//转换成c字符串
- 字符串的简单格式化输出
NSString *name=@"kobe": int age=38; NSLog(@"hello I'am %@,I'am $d years old",name,age);hello I'an kobe,I'an 30 years old
- 字符串的拼接
NSString *str1=@"hello": NSString *str2=@"world"; NSString *Str3=[str1 stringByAppendingString:str2];
- 字符串的大小写转换
NSString *str=@"hello"; NSString *str2=[str uppercaseString]; NSLog(@"after change=%@",str2);//HELLO NSString *str3=[str2 lowercaseString]; NSLog(@"after change=%@",str3);//hello
- 是否包涵前缀
NSString *str=@"kobe is a NBA player"; BOOL hasPrefix=[str hasPrefix:@"kobe"]; NSLog(@"result=%@",hasPrefix); BOOL hasSuffix=[str hasSuffix:@"player"]; NSLog(@"result=%@",hasSuffix);
- 文件的读写
NSString *fileUrl=@"your path": NSString *fileStr=[NSString stringWithContentsOfFile:fileUrl encoding:NSUTF8StringEncoding error:nil]; NSLog(@"file Contents is:%@",fileStr); NSString *needWriteString=@"hello android,I'am ios"; BOOL isSuccess=[needWriteString writeToFile:@"your path" atomically:YES encoding:NSUTF8StringEncoding error:nil]; if(isSuccess){ NSLog(@"write success"); }else{ NSLog(@"write failure"); }
未完待续
0 0
- Objective-C学习笔记-NSString
- Objective-c学习笔记04——NSString
- Objective-C 学习笔记 02 - NSString和NSArray
- Objective-C学习笔记(二)------NSString和NSMutableString类
- Objective-C 学习笔记 06 - 通过NSString和NSData将数据写入文件
- 黑马程序员----Objective-C学习笔记之NSString类的内存管理问题
- objective-c NSString && NSData
- objective-c之NSString
- Objective-C NSString
- Objective-C NSString--(1)
- Objective-C NSString--(2)
- Objective-C----NSString 、 NSMutableString
- Objective-C NSString 操作
- Objective-C 字符串NSString
- Objective-C NSString/字符串
- Objective-C NSString
- Objective-C 基础 NSString
- Objective-C字符串NSString
- java爬虫-Jsoup01
- VELT-0.2.8对STM32开发的支持(4):链接与调试
- Acitivity和Service之间消息的传递
- ES-Hadoop学习笔记-初识
- GDI-图形设备接口
- Objective-C学习笔记-NSString
- Java NIO 系列:Java NIO Path
- 身为网络编辑,你知道这些SEO技巧吗?
- bzoj4562【HAOI2016】食物链
- ListView显示第一条数据
- (id,pid)格式数据转树和森林结构工具类设计与实现
- Android一键清除其他应用缓存数据,有没有什么好方法?
- API之NetworkInfo解释
- 基于ZigBee和STM32的智能家居控制系统的设计与实现(五)--终结篇