Foundation --- 字符串的获取
来源:互联网 发布:淘宝网店卖的钱在哪里 编辑:程序博客网 时间:2024/05/16 12:14
#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... //1.获取字符串的长度 NSString *str = @"ding";// NSUInteger length = [str length]; NSUInteger length = str.length; NSLog(@"字符串长度:%lu",length); //2.根据索引获得单个字符 NSString *str2 = @"www.summer.hello"; //如果定的索引值,超出了字符串的长度,会导致异常Range or index out of bounds unichar c = [str2 characterAtIndex:9]; NSLog(@"字符c:%c",c); //3.根据索引获得一个字串 NSString *str3 = @"www.summer.hello"; NSString *tempStr = [str3 substringFromIndex:3]; //substringFromIndex 从指定的索引开始(包含该索引位置)截取到字符串末尾 NSLog(@"substringFromIndex:%@",tempStr); NSString *tempStr2 = [str3 substringToIndex:3]; //substringToIndex 截取字符串到给定的位置结束,不包含该索引位置 NSLog(@"substringToIndex:%@",tempStr2); NSString *tempStr3 = [str3 substringWithRange:NSMakeRange(0, 3)]; //substringWithRange:NSMakeRange(0, 3) 从第零个字符串开始截取,长度为3个字符 NSLog(@"substringWithRange:%@",tempStr3); //4.获取字符串的某一段 NSRange rang = {4,6};//{location,length} NSString *tempStr4 = [str3 substringWithRange:rang]; NSLog(@"substringWithRange:%@",tempStr4); //5.获得一个字符串的位置 NSString *tempStr5 = @"summer"; NSRange tempRange = [str3 rangeOfString:tempStr5]; NSLog(@"location:%ld,length:%ld",tempRange.location,tempRange.length); if (tempRange.length == NSNotFound) { NSLog(@"temp5 不在 str3 中"); } else { NSLog(@"rangOfString %@",NSStringFromRange(tempRange)); } //6.获得一个字符串索引范围 NSRange tempRange2 = [str3 rangeOfString:@"summer" options:NSCaseInsensitiveSearch]; NSLog(@"rangOfstring1 %@",NSStringFromRange(tempRange2)); } return 0;}
0 0
- Foundation --- 字符串的获取
- Cocoa Foundation 框架:NSString字符串的使用
- Foundation框架中字符串的创建
- Foundation——字符串
- Foundation框架—字符串
- OC之Foundation字符串
- Foundation框架—字符串
- Foundation -- OC字符串
- Foundation框架-字符串
- Foundation——字符串
- Foundation框架—字符串
- Foundation框架—字符串
- Foundation——字符串
- Foundation框架—字符串
- 4 Foundation和带属性的字符串(1)
- 4 Foundation和带属性的字符串(2)
- 4 Foundation和带属性的字符串(3)
- OC的Foundation框架-字符串(NSString与NSMutableString)
- IOS 版本号大小比较
- SecureCRT无法连接VirtualBox中CentOS,报错为:“The remote system refused the connection.”
- Android Binder 通信机制学习(四)
- 在SAE(新浪云平台)上使用 python django库编写网站
- VS2010新建项目失败
- Foundation --- 字符串的获取
- 经典50例,可以参考一下!
- “服务器推”之websocket实现之简单聊天室
- 怎么给文件夹加密
- Android开发adb命令含义
- R语言简介,环境配置与简易使用
- Verilog与SystemVerilog编程陷阱:如何避免101个常犯的编码错误
- Bootstrap + Font Awesome
- listview优化问题