OC中的NSNumber、NSArray、NSString的常用方法
NSString *str11 = @"name";
NSLog(@"%@",str2);
NSString *str22 = @"name";
NSLog(@"%@",str22);
NSLog(@"%@",str3);
NSString *str4 = [NSString stringWithCString:cStr encoding:NSUTF8StringEncoding];
NSLog(@"%@",str4);
NSLog(@"%@",str5);
NSString *str6 = [NSString stringWithFormat:@"%@+%d",@"duke",1001];
NSLog(@"%@",str6);
NSLog(@"%@",str7);
NSString *str8 = [NSString stringWithContentsOfFile:@"/Users/lanouhn/Desktop/未命名.txt" encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",str8);
NSLog(@"%ld",length);
NSLog(@"%@",result1 ? @"YES" : @"NO");
NSLog(@"%@",result2 ? @"YES" : @"NO");
NSLog(@"%@",result3 ? @"YES" : @"NO");
NSLog(@"%ld",result4);//升序为-1,降序为1,相同为0
NSLog(@"%@",subStr1);
NSLog(@"%@",subStr2);
// NSRange range = {1,3};
NSString *subStr3 = [str8 substringWithRange:range];
NSLog(@"%@",subStr3);
NSLog(@"%@",newString1);
NSLog(@"%@",newString2);
NSLog(@"%@",newString3);
NSRange range1 = [link rangeOfString:@"pok = _nie"];
NSLog(@"%@",NSStringFromRange(range1));
if (range1.location != NSNotFound) {
NSLog(@"founded");
}
NSInteger integerValue = [numString1 integerValue];
NSLog(@"%ld",integerValue);
NSLog(@"%@",upperCaseStr);
NSLog(@"%@",lowCaseStr);
NSLog(@"%@",mutableStr1);
NSLog(@"%@",mutableStr1);
NSString *resultString = [mutableStr1 stringByAppendingString:@"xxxxx"];
NSLog(@"%@",mutableStr1);
NSLog(@"%@",mutableStr2);
NSLog(@"%@",mutableStr2);
NSLog(@"%@",mutableStr2);
NSString *picName = [NSString stringWithFormat:@"image.png"];
NSString *resultStr = nil;
if ([picName hasSuffix:@"png"]) {
resultStr = [picName stringByReplacingOccurrencesOfString:@"png" withString:@"jpg"];
} else {
resultStr = [picName stringByAppendingString:@".jpg"];
}
NSLog(@"%@",resultStr);
可变字符串
NSMutableString *picture = [NSMutableString stringWithString:picName];
if ([picture hasSuffix:@"png"]) {
[picture replaceCharactersInRange:[picture rangeOfString:@"png"] withString:@"jpg"];
} else {
[picture appendString:@".jpg"];
NSArray *array1 = [[NSArray alloc] initWithObjects:@"1",@2,@"哈哈",nil];
NSLog(@"%@",[array1 description]);
NSArray *array2 = [NSArray arrayWithObjects:@"1",@2,@"☺",nil];
NSLog(@"%@",array2);
//数组的语法糖形式 (literal,字面量)
NSArray *array3 = @[@"1",@2,@"☺"];
NSLog(@"%@",array3);
//获取数组元素个数
NSInteger count = [array3 count];
NSLog(@"%ld",count);
//通过下标获取对应的对象
for (int i = 0; i < [array3 count]; i++) {
// NSLog(@"%@",[array3 objectAtIndex:i]);
NSLog(@"%@",array3[i]);
}
//通过对象去查找他在数组中的下标
NSInteger index = [array3 indexOfObject:@2];
NSLog(@"%ld",index);
NSLog(@"----------------------------------");
NSString *textString = [NSString stringWithContentsOfFile:@"/Users/Duke/Desktop/未命名.txt" encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",textString);
//通过给定的字符串将原有字符串截取成多个子字符串并保存在数组中返回
NSArray *array4 = [textString componentsSeparatedByString:@"\n"];
NSLog(@"%@",array4);
NSLog(@"%@",mutablearray1);
NSMutableArray *mutableArray2 = [NSMutableArray arrayWithArray:array1];
NSLog(@"%@",mutableArray2);
//添加元素
[mutableArray2 addObject:@33];
NSLog(@"%@",mutableArray2);
//插入元素
[mutableArray2 insertObject:@123 atIndex:2];
NSLog(@"%@",mutableArray2);
//替换一个已有元素
[mutableArray2 replaceObjectAtIndex:2 withObject:@"heihei"];
NSLog(@"%@",mutableArray2);
//交换两个对应下标的对象的位置
[mutableArray2 exchangeObjectAtIndex:2 withObjectAtIndex:0];
NSLog(@"%@",mutableArray2);
//删除最后一个对象
[mutableArray2 removeLastObject];
NSLog(@"%@",mutableArray2);
//删除指定元素
[mutableArray2 removeObject:@2];
NSLog(@"%@",mutableArray2);
//删除指定下标的对象
[mutableArray2 removeObjectAtIndex:0];
NSLog(@"%@",mutableArray2);
//删除多个内容
//删除数组中的所有对象
[mutableArray2 removeAllObjects];
NSLog(@"%@",mutableArray2);
//遍历数组
NSArray *array = [NSArray arrayWithObjects:@"one",@"two",@"three",@"four", nil];
for (int index = 0; index < [array count]; index++) {
NSString *string = [array objectAtIndex:index];
NSLog(@"%@",string);
}
NSLog(@"-----------------------");
for (NSString *string in array) {
NSLog(@"%@",string);
}
OC中的NSNumber、NSArray、NSString的常用方法的更多相关文章
- OC中数组类NSArray的详解,常用属性和方法(一)
数组是一个有序的集合,OC中的数组只能存储对象类型, 但是对于对象的类型没有限制. 通过下标访问数组元素,下标从0开始. NSA
- OC中Foundation框架之NSString、NSMutableString
创建方式 )直接赋值 NSString *str =@"abc"; )创建对象 NSString *str2 = [[NSString alloc]init]; str2 =@&q ...
- OC中数组类NSArray的详解,数组的遍历(二)
数组类的便利 1.for循环(大家都会的...) 2.NSEmunerator 3.for in 首先重点说下 第二种NSEmunerator枚举器,系统声明是 @interface NSEnumer ...
- OC中NSDictionary(字典)、NSMutableDictionary(可变字典)、NSSet(集合)、NSMutableSet(可变集合)得常用方法
字典用于保存具有映射关系数据的集合 一个key—value对认为是一个条目(entry),字典是存储key—value对的容器 与数组不同,字典靠key存取元素 key不能重复,value必须是对象 ...
- OC中的字符串常用方法
OC中的字符串常用方法 OC中对字符串进行操作使用了Foundation框架中的NSString类(不可变).NSMutableString类(可变). NSString 1.创建字符串 [objc] ...
- OC中Foundation框架之NSArray、NSMutableArray
NSArray概述 NSArray是OC中的数组类 NSArray特点 )只能存放任意OC对象,并且是有顺序的 )不能存放非OC对象,比如int/float/double/char/enum/stru ...
- OC中@property属性关键字的使用(assign/weak/strong/copy)
OC中@property属性关键字的使用(assign/weak/strong/copy) 一.assign 用于 ‘基本数据类型’.‘枚举’.‘结构体’ 等非OC对象类型 eg:int.bool等 ...
- OC中文件的操作
OC中文件操作,在之前的文章中,已经接触到了文件的创建了,但是那不是很具体和详细,这篇文章我们就来仔细看一下OC中是如何操作文件的: 第一.首先来看一下本身NSString类给我们提供了哪些可以操作文 ...
- OC中Foundation框架之NSDictionary、NSMutableDictionary
NSDictionary概述 NSDictionary的作用类似:通过一个key ,就能找到对应的value 同样 NSDictionary是不可变的,一旦初始化完毕,里面的内容就无法修改 NSDic ...
随机推荐
- KMP算法浅析
具体参见: KMP算法详解 背景: KMP算法之所以叫做KMP算法是因为这个算法是由三个人共同提出来的,就取三个人名字的首字母作为该算法的名字.其实KMP算法与BF算法的区别就在于KMP算法巧妙的消除 ...
- 003Linux网络配置
基于VMware中的Linux系统: 1.VMware提供了三种网络工作模式: (1)bridged(桥接模式) 桥接模式,顾名思义,得有桥,谁充当桥呢?当然是主机,安装了虚拟机的主机,充当的是虚拟机 ...
- EntityFramework追踪Sql语句
方法一:SQL Profile 这个工具只有sql标准版(standard) 及以上版本才有,我装的是SqlServer2012 Express,所以采用方法2. 方法二:EntityFramewor ...
- 二十、ValueStack的常用方法
二十.ValueStack的常用方法 void set(String key,Object value):先获取根栈栈顶的Map,如果不存在,压入一个新的Map public String execu ...
- Min Stack [LeetCode 155]
1- 问题描述 Design a stack that supports push, pop, top, and retrieving the minimum element in constant ...
- c#中winform的MVP模式的简单实现
MVP模式是类似于MVC模式的一种设计模式,最近在做项目学习过程中遇到,弄了很久终于有一些眉目,这是学习过程中的一些笔记.MVP指的是实体对象Model.视图Viw和业务处理Presenter.MVP ...
- 在Nginx 下运行 Laravel5.1 的配置
一.nginx 的 vhost.conf 配置: server { listen ; server_name sub.domain.com; set $root_path '/srv/www/defa ...
- 解析 this.initialize.apply(this, arguments)
一. 起因 那天用到prototype.js于是打开看看,才看几行就满头雾水,原因是对js的面向对象不是很熟悉,于是百度+google了一把,最后终于算小有收获,写此纪念一下^_^. prototyp ...
- 14)Java中Assert
J2SE 1.4在语言上提供了一个新特性,就是assertion(断言)功能,它是该版本在Java语言方面最大的革新.在软件开发中,assertion是一种经典的调试.测试方式. jvm 断言默认是关 ...
- List集合实战总结
//构造被分隔的集合 List<object> list = new List<object>(); for (int i = 0; i <= 100; i++) { l ...