Objective-C2.0 学习之路1:NSString
来源:互联网 发布:淘宝客服最重要的三点 编辑:程序博客网 时间:2024/06/18 12:05
NSString *string=[NSString stringWithFormat:@"iPhone 5s" ]; NSString *aString=[NSString stringWithFormat:@"I am %@,I have %ld chars",[string className],(unsigned long)[string length],nil]; NSLog(@"%@",aString);
NSString *str=@"哈喽world";//NSString*转换成char* char *strToChar=[str cStringUsingEncoding:[NSString defaultCStringEncoding]]; NSLog(@"%s %s",strToChar,[str UTF8String]);
const char *ch="hello world哈";//char*转换成NSString* NSString *charToStr=[NSString stringWithCString:ch encoding:NSUTF8StringEncoding]; NSLog(@"%@",charToStr);
NSString *path=@"/tmp/scratch.tiff"; path = [path stringByDeletingLastPathComponent];//返回上一级 NSLog(@"%@",path);
NSString *myString=@"Hello World."; NSLog(@"%@",[myString uppercaseString]);//全部改成大写 NSLog(@"%@",[myString lowercaseString]);//全部改成小写 NSLog(@"%@",[myString capitalizedString]);//每个单词首字母改成大写
NSString *myString=@"Hello world"; NSLog(@"%@",[myString substringFromIndex:4]);//从第个字符开始截取,包括第个 NSLog(@"%@",[myString substringToIndex:7]);//截取到第个字符,不包括第个 NSLog(@"%@",[myString substringWithRange:NSMakeRange(4, 3)]);//从第个开始截取个,包括开始的字符
NSString *myString=@"Hello world!"; if ([myString hasPrefix:@"He"])//判断是否为前缀,返回bool型 { NSLog(@"OK"); } if ([myString hasSuffix:@"ld!"])//判断是否为后缀,返回bool型 { NSLog(@"OK"); }
延伸阅读博客:http://xys289187120.blog.51cto.com/3361352/676665
0 0
- Objective-C2.0 学习之路1:NSString
- Objective-C2.0 学习之路2:类
- Objective C2.0学习(一)
- Objective C2.0学习(七 类)
- Objective C2.0学习(八 继承)
- Objective C2.0学习(十 多态)
- Objective C2.0学习(一)
- Objective C2.0学习(七 类)
- Objective C2.0学习(八 继承)
- Objective C2.0学习(十 多态)
- 【iOS】objective-c2.0之基本数据类型
- 【学习ios之路:Objective-C】NSString和NSMutableString
- Objective C2.0学习(二 类,对象和方法)
- Objective C2.0学习(三 类,对象和方法)
- Objective C2.0学习(四 数据类型和表达式)
- Objective C2.0学习(五 循环结构)
- Objective C2.0学习(六 选择结构)
- Objective C2.0学习(九 重载方法)
- 安卓开发小功能段
- alfresco 4.2.e(postgreSQL 数据库)在linux系统安装过程
- chcon命令
- 如何调试int argc,char** argv
- Hibernate的查询 HQL查询 参数,分页,分组,占位符
- Objective-C2.0 学习之路1:NSString
- 自用双索引map
- eclipse中的.project 和 .classpath文件的具体作用
- 模版—素数表
- poj 2739
- Unity 程序员推荐书目
- javascript 操作cookie
- Ubuntu下RPM should not be used directly install RPM packages, use Alien instead!
- Intent系统广播集合