转载于:http://www.cnblogs.com/zhucunliang/archive/2013/11/09/3416039.html

//1、init初始化

NSString * str1 = [[NSString alloc] init];

NSLog(@"str1 = %@",str1);

//2、initWithBytes:length:encoding:从给定字符串按照给定获取方向,得到指定个数的字符

NSString * str2 = [[NSString alloc] initWithBytes:"afasffaf" length:6 encoding:NSUTF8StringEncoding];

NSLog(@"str2 = %@",str2);

//3、initWithCharacters:length:从一个C语言字符串获得lenth个元素

UniChar s[8] = {'e','4','g','d','d','g'};

NSString * str3 = [[NSString alloc] initWithCharacters:s length:4];

NSLog(@"str3 = %@",str3);

//4、initWithCString:encoding:按照方向从一个C语言字符串获得元素

NSString * str4 = [[NSString alloc] initWithCString:"fasfa" encoding:NSUTF8StringEncoding];

NSLog(@"str4 = %@",str4);

//5、initWithUTF8String:初始化,用UTF8格式String

NSString * str5 = [[NSString alloc] initWithUTF8String:"ARQWRT"];

NSLog(@"str5 = %@",str5);

[str5 release];

//6、initWithFormat:用给定字符串初始化

NSString * str6 = [[NSString alloc] initWithFormat:@"QRQWTQT"];

[str6 release];

// 7、stringWithFormat:便利构造器

NSString * str7 = [NSString stringWithFormat:@"qqqqqq"];

[str7 release];

//8、stringWithCharacters:length:从C语言字符串获取length个字符

NSString * str8 = [NSString stringWithCharacters:s length:2];

//9、stringWithString:字符串初始化字符串

NSString * str9 = [NSString stringWithString:str8];

[str9 release];

//10、stringWithCString:encoding:便利构造器创建字符串

NSString * str10 = [NSString stringWithCString:"sasfaf" encoding:NSUTF8StringEncoding];

NSLog(@"str10 = %@",str10);

//11、stringWithUTF8String:便利构造器创建字符串

NSString * str11 = [NSString stringWithUTF8String:"qw   er"];

// 12、length字符串长度

unsigned long result = [str11 length];

NSLog(@"result = %ld",result);

//13、lengthOfBytesUsingEncoding:

unsigned long a = [str11 lengthOfBytesUsingEncoding:NSUTF16StringEncoding];

NSLog(@"a = %ld",a);

//14、characterAtIndex:指定下标的字符

UniChar a1 = [str11 characterAtIndex:2];

NSLog(@"a1 = %hd",a1);

//15、getCharacters:range:获取一定范围内的字符

NSRange ran = NSMakeRange(1, 2);

[str11 getCharacters:s range:ran];

for (int i = 0; i < ran.length; i++) {

NSLog(@"s[i] = %c",s[i]);

}

//16、cStringUsingEncoding:以一定格式转成C字符串

const char * p1 = [str11 cStringUsingEncoding:NSUTF8StringEncoding];

NSLog(@"p1 = %s",p1);

//17、UTF8String

const char * p2 = [str11 UTF8String];

NSLog(@"p2 = %s",p2);

//18、stringByAppendingFormat:添加字符

NSString * str12 = [str11 stringByAppendingFormat:@"aaaaaa"];

//19、stringByAppendingString:用字符串添加

NSString * str13 = [str12 stringByAppendingString:str11];

//20、stringByPaddingToLength:withString:startingAtIndex:创建一个新字符串,长度为length,旧字符串从索引字符开始拷贝到旧字符串后面

NSString * str14 = [str13 stringByPaddingToLength:20 withString:str13 startingAtIndex:1];

NSLog(@"str14 = %@",str14);

//21、componentsSeparatedByString://返回一个数组,字符串字串被给定的字符串分存到数组里

NSString * str15 = @"affaf, rq, 41wre";

NSArray * array = [str15 componentsSeparatedByString:@" "];

NSLog(@"%@",array);

//22、componentsSeparatedByCharactersInSet:用指定字符分割

NSArray * array1 = [str15 componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" "]];

NSLog(@"%@",array1);

//23、substringFromIndex:获得指定下标的子字符串

NSString * str16 = [str14 substringFromIndex:10];

NSLog(@"str16 = %@",str16);

//24、substringWithRange:一定范围的字符串,字串

NSRange ran1 = NSMakeRange(2, 4);

NSString * str17 = [str14 substringWithRange:ran1];

NSLog(@"str17 = %@",str17);

//25、substringToIndex:到指定下标的字串

NSString * str18 = [str14 substringToIndex:10];

NSLog(@"str18 = %@",str18);

//26、rangeOfString:字符串范围

NSRange ran2 = [str14 rangeOfString:@"aaaqwe"];

NSLog(@"location = %ld,lenth = %ld",ran2.location,ran2.length);

//27、rangeOfString:options:从指定方向查找字符串,返回范围

NSRange ran3 = [str14 rangeOfString:@"qweraaaa" options: NSBackwardsSearch];

NSLog(@"location = %ld,lenth = %ld",ran3.location,ran3.length);

// 28、rangeOfString:options:range:从指定方向指定范围查找字符串,返回范围

NSRange ran4 = [str14 rangeOfString:@"raaaaa" options:NSBackwardsSearch range:NSMakeRange(1,
15)];

NSLog(@"location = %ld,lenth = %ld",ran4.location,ran4.length);

//29、stringByReplacingOccurrencesOfString:withString:指定范围内的字串用给定的字符串替换

NSString * string = @"qqqqqqq";

NSString * str20 = [str14 stringByReplacingCharactersInRange:ran2 withString:string];

NSLog(@"str20 = %@",str20);

//30、stringByReplacingOccurrencesOfString:withString:options:range:按照指定方向,在指定范围内的指定字符串替换成给定字符串

NSString * str21 = [str14 stringByReplacingOccurrencesOfString:@"aaa" withString:@"AAAA" options:NSBackwardsSearch range:NSMakeRange(1,
10)];

NSLog(@"str21 = %@",str21);

//31、stringByReplacingCharactersInRange:withString:指定范围内的字符串用给定那个字符串替换

NSString * str22 = [str14 stringByReplacingCharactersInRange:ran1 withString:@"AAAAA"];

NSLog(@"str22 = %@",str22);

//32、caseInsensitiveCompare:字符串比较

NSComparisonResult temp = [str14 caseInsensitiveCompare:@"qweraav"];

NSLog(@"temp = %ld",temp);

//33、compare:字符串比较

NSComparisonResult temp1 = [str14 compare:@"aaaa"];

NSLog(@"temp1 = %ld",temp1);

//34、compare:options:指定方向比较

NSComparisonResult temp2 = [str14 compare:@"zzzzz" options:NSBackwardsSearch];

NSLog(@"temp2 = %ld",temp2);

//35、compare:options:range:指定方向,指定范围字符串与给定字符串比较

NSComparisonResult temp3 = [str14 compare:@"zzzz" options:NSBackwardsSearch range:NSMakeRange(3,
4)];

NSLog(@"temp3 = %ld",temp3);

//36、hasPrefix:判断字符串是否以指定字符串开头

if ([str14 hasPrefix:@"qwe"]) {

NSLog(@"yes");

}

//37、hasSuffix:判断字符串是否以指定字符串结束

if ([str14 hasSuffix:@"abc"]) {

NSLog(@"yes");

}else{

NSLog(@"no");

}

//38、isEqualToString:比较字符串是否相等

if ([str14 isEqualToString:@"qwertty"]) {

NSLog(@"yes");

}else{

NSLog(@"no");

}

//39、capitalizedString//首字母大写

NSString * str23 = [str14 capitalizedString];

NSLog(@"str23 = %@",str23);

//40、lowercaseString全转小写

NSString * str24 = [str14 lowercaseString];

NSLog(@"str24 = %@",str24);

//41、uppercaseString//全转大写

NSString * str25 = [str14 uppercaseString];

//42、doubleValue

NSString * str26 = @"a2797.79";

double d1 = [str26 doubleValue];

NSLog(@"d1 = %lf",d1);

//43、floatValue

float d2 = [str26 floatValue];

NSLog(@"d2 = %lf",d2);

//44、intValue

int d3 = [str26 intValue];

//45、integerValue

unsigned long d4 = [str26 integerValue];

NSLog(@"d4 = %ld",d4);

//46、longLongValue

long long d5 = [str26 longLongValue];

NSLog(@"d5 = %lld",d5);

//47、boolValue //遇到"Y", "y", "T", "t"或者数字返回YES

NSString * str27 = @"afa";

BOOL bo = [str27 boolValue];

if (bo) {

NSLog(@"yes");

}

NSLog(@"%@",str14);

NSLog(@"%@",str25);

NSLog(@"d2 = %.2d",d3);

NSLog(@"d5 = %ld",d4);

//48、stringWithCapacity:便利构造器创建可变字符串

id mustr = [NSMutableString stringWithCapacity:10];

//49、initWithCapacity:初始化一个可变字符串

NSMutableString * mustr1 = [[NSMutableString alloc] initWithCapacity:20];

//50、appendFormat:追加字符串

[mustr1 appendFormat:@"affgf"];

NSLog(@"%@",mustr1);

//51、appendString:用字符串追加到旧字符串上

[mustr appendString:mustr1];

NSLog(@"%@",mustr);

//52、deleteCharactersInRange:删除指定范围内的字符串

[mustr deleteCharactersInRange:NSMakeRange(1, 2)];

NSLog(@"%@",mustr);

//53、insertString:atIndex:在指定下标除插入字符串

[mustr1 insertString:mustr atIndex:0];

NSLog(@"mustr1 = %@",mustr1);

//54、replaceCharactersInRange:withString:用给定字符串替换原串指定范围内的字符串

[mustr1 replaceCharactersInRange:NSMakeRange(1, 7) withString:@"agqrqrqe"];

NSLog(@"mustr1 = %@",mustr1);

//55、replaceOccurrencesOfString:withString:options:range:从指定方向开始,遇到要被替换的字符串,用替换字符串替换它,并返回被替换字符串在原来字符串的开始位置下标

NSUInteger i = [mustr1 replaceOccurrencesOfString:@"aagq" withString:@"zaz" options:NSBackwardsSearch range:NSMakeRange(0,
4)];

NSLog(@"mustr1 = %@",mustr1);

NSLog(@"i = %ld",i);

//56、setString:字符串重置

[mustr1 setString:@"fffffff"];

// NSArray

//1、array便利构造器

id myarray = [NSArray array];

NSLog(@"myarray = %@",myarray);

// 2、arrayWithArray:便利构造器方法,用一个数组初始化数组

NSArray * ar1 = [NSArray arrayWithObject:@"aaaaa"];

NSArray * ar2 = [NSArray arrayWithArray:ar1];

NSLog(@"ar2 = %@",ar2);

//3、arrayWithObject:一个元素初始化数组

NSArray * ar3 = [NSArray arrayWithObject:@"sssss"];

NSLog(@"ar3 = %@",ar3);

//4、arrayWithObjects:多个元素初始化数组

NSArray * ar4 = [NSArray arrayWithObjects:@"qwer",@"asdf",@"zxcv",
nil];

NSLog(@"ar4 = %@",ar4);

//5、arrayWithObjects:count:用指定元素个数,初始化数组,注意参数

NSString * strings[3] = {@"qwe",@"asd",@"zxc"};

NSArray * ar5 = [NSArray arrayWithObjects:strings count:3];

//6、init

//7、initWithArray:用数组初始化数组

NSArray * ar6 = [[NSArray alloc] initWithArray:ar5];

[ar6 release];

//8、initWithObjects:给定多个对象初始化数组

NSArray * ar7 = [[NSArray alloc] initWithObjects:@"qwer",@"asdf",@"zxcv",nil];

[ar7 release];

//9、initWithObjects:count:初始化一个数组,给定元素个数(参数const id [])

NSArray * ar8 = [[NSArray alloc] initWithObjects:strings count:3];

//10、containsObject:判断是否含有指定元素

if([ar8 containsObject:@"qwe"]){

NSLog(@"yes");

}

//11、count数组元素个数

unsigned long b = [ar8 count];

NSLog(@"%ld",b);

//12、getObjects:range:返回一个数组,给定一个范围,在原数组里逐一获取元素到接收数组

id *obj;

NSRange range1 = NSMakeRange(1, 2);

obj = malloc(sizeof(id)*range1.length);

[ar8 getObjects:obj range:range1];

for (int i = 0; i < range1.length; i++) {

NSLog(@"obj = %@",obj[i]);

}

free(obj);

//13、firstObject返回一个数组--原数组的第一个元素

NSLog(@"ar8 = %@",ar8);

NSArray * ar10 = [ar8 firstObjectCommonWithArray:ar8];

NSLog(@"ar10 = %@",ar10);

//14、lastObject返回数组最后一个元素

NSArray * ar11 = [ar8 lastObject];

[ar11 release];

//15、objectAtIndex:返回指定索引值的元素

NSArray * ar13 = [ar8 objectAtIndex:1];

NSLog(@"ar13 = %@",ar13);

//16、objectsAtIndexes:返回一个数组,指定索引值的元素

NSIndexSet * ss = [NSIndexSet indexSetWithIndex:2];

NSArray * ar14 = [ar8 objectsAtIndexes:ss];

NSLog(@"ar14 = %@",ar14);

//17、objectEnumerator 返回索引,可以根据返回索引值输出数组元素

NSEnumerator * enum1 = [ar8 objectEnumerator];

id myobj;

while (myobj = [enum1 nextObject]) {

NSLog(@"obj = %@",myobj);

}

//18、reverseObjectEnumerator反向获取下标,返回下标值,可以反向输出数组元素

NSEnumerator * enum2 = [ar8 reverseObjectEnumerator];

id myobj1;

while (myobj1 = [enum2 nextObject]) {

NSLog(@"obj1 = %@",myobj1);

}

//19、indexOfObject:返回元素下标

unsigned long temp19 = [ar8 indexOfObject:@"asd"];

NSLog(@"temp 19 = %ld",temp19);

//20、indexOfObject:inRange:在指定范围内找出给定对象,返回下标值

unsigned long temp20 = [ar8 indexOfObject:@"asd" inRange:NSMakeRange(1,
1)];

NSLog(@"temp20 = %ld",temp20);

//21、makeObjectsPerformSelector:

//22、makeObjectsPerformSelector:withObject:

//23、firstObjectCommonWithArray:第一个相同的元素

NSArray * ar22 = [NSArray arrayWithObjects:@"qeqe",@"asd",nil];

id ar23 = [ar8 firstObjectCommonWithArray:ar22];

NSLog(@"ar23 = %@",ar23);

// 24、isEqualToArray:比较是否相等

if ([ar8 isEqualToArray:ar22]) {

NSLog(@"yes");

}else{

NSLog(@"no");

}

//25、arrayByAddingObject:将指定对象添加到数组

NSArray * ar25 = [ar8 arrayByAddingObject:@"tyu"];

NSLog(@"ar25 = %@",ar25);

//26、arrayByAddingObjectsFromArray:从一个数组添加元素

NSArray * ar26 = [ar8 arrayByAddingObjectsFromArray:ar25];

NSLog(@"ar26 = %@",ar26);

//27、sortedArrayUsingFunction:context:

//28、sortedArrayUsingDescriptors:

//29、sortedArrayUsingSelector:

//30、componentsJoinedByString:用指定对象,符号分割数组元素

NSString * string30 = [ar8 componentsJoinedByString:@"--"];

NSLog(@"string30 = %@",string30);

//31、arrayWithCapacity:便利构造器创建一个可变数组

NSMutableArray * mar1 = [NSMutableArray arrayWithCapacity:20];

//32、initWithCapacity:初始化可变数组

NSMutableArray * mar2 = [[NSMutableArray alloc] initWithCapacity:20];

//33、addObject:向可变数组添加给定对象

[mar1 addObject:@"afgh"];

NSLog(@"mar1 = %@",mar1);

//34、addObjectsFromArray:从数组中向可变数组添加对象

[mar2 addObjectsFromArray:ar8];

NSLog(@"mar2 = %@",mar2);

//35、insertObject:atIndex:在指定下标除增加一个对象

[mar2 insertObject:@"qqq" atIndex:2];

NSLog(@"mar2 = %@",mar2);

//36、removeAllObjects移除可变数组内的所有对象

[mar1 removeAllObjects];

NSLog(@"mar1 = %@",mar1);

//37、removeLastObject//移除可变数组最后一个对象

[mar2 removeLastObject];

NSLog(@"mar2 = %@",mar2);

//38、removeObject:从可变数组内移除给定对象

[mar2 removeObject:@"qqq"];

NSLog(@"mar2 = %@",mar2);

//39、removeObject:inRange:移除指定范围内的一个对象

[mar2 removeObject:@"qwe" inRange:NSMakeRange(0,
1)];

NSLog(@"mar2 = %@",mar2);

//40、removeObjectAtIndex:移除指定下标的元素

[mar2 addObjectsFromArray:ar8];

NSLog(@"mar2 = %@",mar2);

[mar2 removeObjectAtIndex:3];

NSLog(@"mar2 = %@",mar2);

//41、removeObjectsInArray:将给定数组的元素从可变数组中全部移除

[mar2 removeObjectsInArray:ar8];

NSLog(@"mar2 = %@",mar2);

[mar2 addObjectsFromArray:ar8];

NSLog(@"mar2 = %@",mar2);

//42、removeObjectsInRange:移除给定范围内的所有元素

[mar2 removeObjectsInRange:NSMakeRange(0, 1)];

NSLog(@"mar2 = %@",mar2);

//43、replaceObjectAtIndex:withObject:用给出的对象替换指定下标的元素

[mar2 replaceObjectAtIndex:1 withObject:@"kkkkk"];

NSLog(@"mar2 = %@",mar2);

//44、setArray:重置可变数组

[mar2 setArray:ar8];

NSLog(@"mar2 = %@",mar2);

//exchangeObjectAtIndex:withObjectAtIndex:指定下标的两个元素交换

[mar2 exchangeObjectAtIndex:2 withObjectAtIndex:1];

NSLog(@"mar2 = %@",mar2);

ios开发中一些常用API总结的更多相关文章

  1. iOS开发中的常用宏定义

    在iOS开发的过程中合理的使用宏定义能够极大提高编码的速度,下面是一些常用的宏定义,部分内容来自互联网 Log // 调试状态, 打开LOG功能 #ifdef DEBUG #define GLLog( ...

  2. IOS开发中Xcode常用插件安装与管理(转)

    XCode中插件管理工具:Alcatraz    转自http://www.cocoachina.com/industry/20140506/8325.html 苹果现在的成绩得益于其始终如一的坚持. ...

  3. iOS开发中数组常用的五种遍历方式

    随着iOS的不断发展,apple也不断推出性能更高的数组遍历方式,下面将对熟悉的五种遍历方式进行列举. 首先定义一个数组,并获取数组长度 NSArray *array=@[",]; NSIn ...

  4. iOS开发中一些常用的方法

    1.压缩图片 #pragma mark 处理图片 - (void)useImage:(UIImage *)image { NSLog(@"with-----%f heught-----%f& ...

  5. iOS开发中常用的数学函数

    iOS开发中常用的数学函数 /*---- 常用数学公式 ----*/ //指数运算 3^2 3^3 NSLog(,)); //result 9 NSLog(,)); //result 27 //开平方 ...

  6. 多线程在iOS开发中的应用

    多线程基本概念 01 进程 进程是指在系统中正在运行的一个应用程序.每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内. 02 线程 2-1 基本概念 1个进程要想执行任务,必须得有线程 ...

  7. iOS开发中的MVC设计模式

    我们今天谈谈cocoa程序设计中的 模型-视图-控制器(MVC)范型.我们将从两大方面来讨论MVC: 什么是MVC? M.V.C之间的交流方式是什么样子的? 理解了MVC的概念,对cocoa程序开发是 ...

  8. [转]iOS开发中的火星坐标系及各种坐标系转换算法

     iOS开发中的火星坐标系及各种坐标系转换算法 源:https://my.oschina.net/u/2607703/blog/619183   其原理是这样的:保密局开发了一个系统,能将实际的坐标转 ...

  9. iOS开发中打电话发短信等功能的实现

    在APP开发中,可能会涉及到打电话.发短信.发邮件等功能.比如说,通常一个产品的"关于"页面,会有开发者的联系方式,理想情况下,当用户点击该电话号码时,能够自动的帮用户拨出去,就涉 ...

随机推荐

  1. BZOJ1878 SDOI2009 HH的项链 【莫队】

    BZOJ1878 SDOI2009 HH的项链 Description HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步 完后,他都会随意取出一段贝壳,思考它们所表达的 ...

  2. 《selenium2 python 自动化测试实战》(12)——跳过验证码登录add_cookie

    微信公众号搜索“自动化测试实战”或扫描下方二维码添加关注~~~

  3. 同一台电脑上装两个或两个以上的tomcat服务器

    1.下载免安装版tomcat,解压成tomcat1.tomcat2: 2.修改tomcat2中conf下server.xml文件如下: <Server port="8005" ...

  4. Sprint第一个冲刺(第六天)

    一.Sprint介绍 今天我们完成了修改注册和登录直接用滚轮选择,主界面加入轮播图 . 实验截图: 主界面加入轮播图: 任务进度: 二.Sprint周期 看板: 燃尽图:

  5. [LeetCode系列]子集枚举问题[无重复元素]

    给定一组数(未排序), 求它们的所有组合可能. 如给定{1 2 3}, 返回: [ [] [1] [2] [3] [1 2] [1 3] [2 3] [1 2 3] ] 算法思路: 对数组排序, 从小 ...

  6. bzoj5248(洛谷4363)(2018九省联考)一双木棋

    题目:https://www.luogu.org/problemnew/show/P4363 一种考虑状态数的方法:有几个用了k个格子的列,就在第k个0的左边插入几个1: 这也是求不降序列的个数的方法 ...

  7. 教你30分钟学会XAML

    1.狂妄的WPF 相对传统的Windows图形编程,需要做很多复杂的工作,引用许多不同的API.例如:WinForm(带控件表单).GDI+(2D图形).DirectX API(3D图形)以及流媒体和 ...

  8. JVM内存管理之GC算法精解(复制算法与标记/整理算法)

    本次LZ和各位分享GC最后两种算法,复制算法以及标记/整理算法.上一章在讲解标记/清除算法时已经提到过,这两种算法都是在此基础上演化而来的,究竟这两种算法优化了之前标记/清除算法的哪些问题呢? 复制算 ...

  9. VC编译选项 md /mdd /ml /mt/mtd

    VC编译选项 多线程(/MT)多线程调试(/MTd)多线程 DLL (/MD)多线程调试 DLL (/MDd)C 运行时库                        库文件Single threa ...

  10. bc显示小数点前的0

    bc是强大而常用的计算工具.不过在除法运算时,如果得到的结果值小于1,得到的小数前面的0不存.本篇提供几个常用小数点前缺0的解决方法. [root@maqing ~]# bc bc Copyright ...