//初始化//iniWithString------ReturnsanNSStringobjectinitializedbycopyingthecharactersfromanothergivenstring.//返回一个NSString对象初始化复制来自另一个给定字符串的字符。NSString*str=@"liuyafang";NSString*str1=[[NSStringalloc]initWithString:str];NSLog(@"str1=%@",str1);//计算字符串长度//length------ReturnsthenumberofUnicodecharactersinthereceiver.//返回接收器中Unicode字符的数量NSIntegercount=[strlength];//可见长度NSLog(@"%ld",count);//initWithFormat://ReturnsanNSStringobjectinitializedbyusingagivenformatstringasatemplateintowhichtheremainingargumentvaluesaresubstituted.//返回一个NSString对象初始化使用给定的格式字符串作为模板,其余参数值代替。NSString*str2=@"dapingmu";NSString*str3=[[NSStringalloc]initWithFormat:@"liuyafang"];NSLog(@"str2=%@",str2);NSLog(@"str3=%@",str3);//判断是否以指定字符开头或者结尾BOOLpre=[str3hasPrefix:@"liu"];NSLog(@"%d",pre);BOOLsuf=[str3hasSuffix:@"fang"];NSLog(@"%d",suf);//截取字符串的长度和起始位置----Findsandreturnstherangeofthefirstoccurrenceofagivenstringwithinthereceiver.//NSRangerag=[str3rangeOfString:@"liu"];NSLog(@"length=%ld,lacation=%ld",rag.length,rag.location);//截取从输入的起始位置开始输出NSString*sub=[str3substringFromIndex:3];NSLog(@"%@",sub);//截取到输入的位置并输出NSString*subb=[str3substringToIndex:3];NSLog(@"%@",subb);//截取一个范围字符串NSRangeaa={0,4};NSString*ran1=[str3substringWithRange:aa];NSString*ran=[str3substringWithRange:NSMakeRange(0,5)];//NSMakeRange(0,5)范围的起始位置和末尾位置NSLog(@"%@",ran1);NSLog(@"%@",ran);//拼接字符串NSString*str4=@"verygood!";NSString*app=[strstringByAppendingString:str4];NSLog(@"%@",app);NSLog(@"%@",str);NSString*b=[strstringByAppendingFormat:@"%@==%d",str,5];//格式化拼接,,,有问题,,NSLog(@"%@",b);//替换字符串NSString*rep=[str3stringByReplacingOccurrencesOfString:@"ya"withString:@"xiao"];NSLog(@"%@",rep);//转换成小写的NSString*lowe=[@"ljlkmJNnhjnHhhbhHnbjjbnghUKJkj"lowercaseString];NSLog(@"%@",lowe);//首字母转换成大写;NSString*cap=[@"adHjdaajdaajdlla"capitalizedString];NSLog(@"%@",cap);NSMutableString*mutabal=[NSMutableStringstringWithCapacity:5];NSLog(@"%@",mutabal);NSMutableString*mutabal1=[NSMutableStringstringWithFormat:@"liuyafang"];NSLog(@"%@",mutabal1);//可变字符串拼接//Addsaconstructedstringtothereceiver.---添加一个构造字符串到接收方。[mutabal1appendFormat:@"good"];NSLog(@"%@",mutabal1);[mutabal1appendFormat:@"%@",@"good"];NSLog(@"%@",mutabal1);//Addstotheendofthereceiverthecharactersofagivenstring.--增加了接收机的最后一个给定字符串的字符。[mutabal1appendString:@"what!"];NSLog(@"%@",mutabal1);[mutabal1stringByAppendingString:@"nimei"];NSLog(@"----------%@",mutabal1);//删除范围字符串//Removesfromthereceiverthecharactersinagivenrange.----删除来自接收者的角色在一个给定的范围内。NSRangeaaa={0,3};[mutabal1deleteCharactersInRange:aaa];NSLog(@"%@",mutabal1);//NSMakeRange-------CreatesanewNSRangefromthespecifiedvalues.--创建一个新的NSRange指定值。[mutabal1deleteCharactersInRange:NSMakeRange(0,3)];NSLog(@"%@",mutabal1);//Replacesthecharactersofthereceiverwiththoseinagivenstring.----替换字符的接收器与给定的字符串。[mutabal1setString:@"liu"];NSLog(@"%@",mutabal1);//作业1。。判断是否以EfGk结尾,如果是替换成WXYZ,然后转变成小写NSString*exercise=@"aBcD_EfGk";BOOLa1=[exercisehasSuffix:@"EfGk"];NSLog(@"%d",a1);NSString*exer=[exercisestringByReplacingOccurrencesOfString:@"EfGk"withString:@"WXYZ"];NSLog(@"---====>%@",exer);NSString*exer1=[exerlowercaseString];NSLog(@"------>%@",exer1);//作业1。2判断是都以png结尾,如果是替换成jpg,如果不是则添加.jpgNSMutableString*page=[NSMutableStringstringWithFormat:@"xiaoliu.png"];BOOLaa11=[pagehasSuffix:@"png"];NSLog(@"%d",aa11);if(aa11==1){NSString*page1=[pagestringByReplacingOccurrencesOfString:@"png"withString:@"jpg"];NSLog(@"%@",page1);}else{[pageappendString:@".jpg"];NSLog(@"%@",page);}//数组初始化,,获取元素个数NSArray*arr=[NSArrayarrayWithObjects:@"ss",@"dd",@"aa",nil];NSLog(@"%@",arr);NSIntegercon=[arrcount];NSLog(@"%ld",con);//根据对象获得所引致//Returnsthelowestindexwhosecorrespondingarrayvalueisequaltoagivenobject.---NSIntegerdd=[arrindexOfObject:@"dd"];NSLog(@"%ld",dd);//根据所引致获得对象//Returnstheobjectlocatedatthespecifiedindex.NSArray*ppp=[arrobjectAtIndex:0];NSLog(@"0000000%@",ppp);///-------------可变数组--------------///NSMutableArray*mutarr=[NSMutableArrayarrayWithCapacity:5];NSLog(@"%@",mutarr);NSMutableArray*mt=[NSMutableArrayarrayWithObjects:@"aaa",@"bbb",@"ccc",@"ddd",nil];NSMutableArray*mm=[NSMutableArrayarrayWithObjects:@"ee",@"qq",nil];NSLog(@"%@",mt);//添加元素//Insertsagivenobjectattheendofthearray.[mtaddObject:@"fff"];NSLog(@"%@",mt);//插入元素//Insertsagivenobjectintothearray'scontentsatagivenindex.[mtinsertObject:@"ooo"atIndex:2];NSLog(@"%@",mt);//数组连接,,,//Addstheobjectscontainedinanothergivenarraytotheendofthereceivingarray’scontent.[mtaddObjectsFromArray:mm];NSLog(@"%@",mt);//删除元素[mtremoveObjectAtIndex:2];NSLog(@"%@",mt);//替换元素[mtreplaceObjectAtIndex:0withObject:@"ttttt"];NSLog(@"%@",mt);//交换两个指定位置对元素[mtexchangeObjectAtIndex:0withObjectAtIndex:1];NSLog(@"%@",mt);//图书管理//NSMutableArray*library=[NSMutableArrayarrayWithObjects:@"tushu1",@"tushu2",@"tushu3",@"tushu4",nil];//NSIntegercount1=[librarycount];//NSIntegerddd;//NSLog(@"1-添加图书2-删除图书3-修改图书4-查找图书5-查看图书");//scanf("%ld",&ddd);//if(ddd==1){//[libraryaddObject:@"tushu5"];//NSLog(@"%@",library);//}//if(ddd==2){//[libraryremoveObject:@"tushu3"];//NSLog(@"%@",library);//}//if(ddd==3){//[librarysetObject:@"tushu0"atIndexedSubscript:0];//NSLog(@"%@",library);//}//if(ddd==4){//NSIntegerplace=[libraryindexOfObject:@"tushu3"];//NSLog(@"%ld",place);//}//if(ddd==5){//for(inti=0;i<count1;i++){//NSLog(@"%@",library[i]);//}//}//正式作业1;NSString*jiequ=@"20|http://www.baidu.com";NSString*neww=[jiequsubstringFromIndex:3];//从这个位置开始截取,截取前面输出后面。NSLog(@"%@",neww);NSString*new=[jiequsubstringToIndex:2];//截取到这个位置NSLog(@"%@",new);//将文件改写成213NSString*qing=@"文艺青年";NSString*a213=[qingstringByReplacingOccurrencesOfString:@"文艺"withString:@"213"];NSLog(@"%@",a213);