//
// main.m
// aa
///Users/zlx/Desktop/OC/aa.xcodeproj
// Created by rcfwzx on 15/11/20.
// Copyright (c) 2015年 rcfwzx. All rights reserved.
//
#import <Foundation/Foundation.h>
#define NSLog(FORMAT, ...) fprintf(stderr,"%s\n",[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *a=@"jjkkllFDSFDaqt";
NSString *b=@"atrGDSass";
//拼接
NSLog(@"--------拼接--------");
NSString *c=[a stringByAppendingString:b];
NSLog(@"拼接%@",c);
NSLog(@"拼接为%@\n\n",[a stringByAppendingString:b]);
//赋值
NSLog(@"--------赋值--------");
NSString *e=[[NSString alloc]init];
e=@"fflls";
NSLog(@"负值为%@\n\n",e);
//格式化
NSLog(@"-------格式化---------");
NSString *c1=[[NSString alloc]initWithFormat:@"%@",c];
// NSString *c1=[[NSString alloc]initWithString:[NSString stringWithFormat:@"%@",c]];
NSLog(@"%@\n\n",c1);
//字符串转数字
NSString *pl=@"55";
NSInteger gg=[pl intValue];
NSLog(@"%ld\n",gg);
//数字转字符串
bool gl=YES;
NSString *gg1=[[NSString alloc]initWithFormat:@"%ld",gg];
NSString *gg2=[[NSString alloc]initWithFormat:@"%i",gl];
NSInteger gl1=[pl integerValue];
NSLog(@"%ld\n",gl1);
NSLog(@"====---%@\n",gg2);
NSLog(@"%@\n",gg1);
//判断是否相等
NSLog(@"------判断是否相等----------");
BOOL c2=[a isEqualToString:b];
if(c2==0)
NSLog(@"不相等\n\n");
else NSLog(@"相等\n\n");
NSLog(@"判断为%i\n\n",[a isEqualToString:b]);
//大写
NSLog(@"--------大写--------");
NSLog(@"大写%@",[a uppercaseString]);
//小写
NSLog(@"-------小写---------");
NSLog(@"小写%@",[a lowercaseString]);
//首字母大写
NSLog(@"-------首字母大写---------");
NSLog(@"首字母%@\n\n",[c capitalizedString]);
//长度
NSLog(@"-------长度---------");
unsigned long a1=[a length];
NSUInteger len=[a length];
NSLog(@"字符%@的长度为%ld\n\n",a,len);
NSLog(@"字符%@的长度为%ld\n\n",a,a1);
//从输入的数字后面开始到尾 显示
NSLog(@"------从输入的数字后面开始到尾 显示----------");
NSString *c4=[a substringFromIndex:4];
NSLog(@"%@\n\n",c4);
//从开始到输入的数字为止 显示
NSLog(@"-------从开始到输入的数字为止 显示---------");
NSString *c5=[a substringToIndex:5];
NSLog(@"%@\n\n",c5);
//从输入的第一个数字后面开始 显示第二数字的数量为止
NSLog(@"---------从输入的第一个数字后面开始 显示第二数字的数量为止-------");
NSString *c7=[a substringWithRange:NSMakeRange(4,3)];
NSLog(@"%@\n\n",c7);
//注释后 为链接地址
// NSString *ll=@"http://acfun.tv";
// NSLog(@"%@",ll);
// const char *ll1=[ll UTF8String];
// NSLog(@"%s",ll1);
//判断字符串前缀
NSLog(@"--------判断字符串前缀--------");
NSString *tu=@"IOS-heihei.jpg";
BOOL tu1=[tu hasPrefix:@"IOS"];
if(tu1==1)
{
NSLog(@"有");
}
else NSLog(@"没有");
//判断字符串后缀
NSLog(@"--------判断字符串后缀--------");
bool tu2=[tu hasSuffix:@"jpg"];
if(tu2==1)
{
NSLog(@"有");
}
else NSLog(@"没有");
//不可变字符串
NSLog(@"--------不可变字符串--------");
NSString *c8=@"dsopliktkkgrt";
//可变字符串
NSLog(@"---------可变字符串-------");
NSMutableString *c9=[[NSMutableString alloc]initWithString:c8];
NSLog(@"可变字符串为%@\n\n",c9);
//插入字符串到另一个字符串
NSLog(@"--------插入字符串到另一个字符串--------");
[c9 insertString:@"ppl" atIndex:3];
NSLog(@"可变字符串为%@\n\n",c9);
//查看
NSLog(@"---------查看-------");
NSRange sub=[c9 rangeOfString:@"k"];
NSLog(@"查看%@\n\n",c9);
NSLog(@"%ld和%ld",sub.length,sub.location);
while (sub.location!=NSNotFound)
{
[c9 deleteCharactersInRange:sub];
sub=[c9 rangeOfString:@"k"];
}
if(sub.location!=NSNotFound)
{
NSLog(@"没找到\n\n");
}
//删除
NSLog(@"-------删除---------");
NSLog(@"删除%@\n\n",c9);
//重新设置字符串
NSLog(@"-------重新设置字符串---------");
[c9 setString:@"kkggpqwe"];
//替换/修改
NSLog(@"--------替换/修改--------");
[c9 replaceCharactersInRange:NSMakeRange(5,3) withString:@"k"];
NSLog(@"替换%@\n\n",c9);
//动态数组1
NSLog(@"--------动态数组1--------");
NSMutableArray *d3=[[NSMutableArray alloc]initWithObjects:@"dda",@"dde",nil];
//倒序
NSLog(@"--------倒序--------");
//字符串转数组
NSMutableString *nn=[[NSMutableString alloc]initWithString:@"ddrrhhq"];
NSMutableArray *nn1=[[NSMutableArray alloc]initWithArray:[nn componentsSeparatedByString:@""]];
NSMutableArray *nn3=[[NSMutableArray alloc]initWithArray:[[nn1 reverseObjectEnumerator]allObjects]];
//数组转字符串
NSString *nn2=[nn3 componentsJoinedByString:@""];
NSLog(@"bb%@",nn3);
NSLog(@"nnn%@",nn2);
NSMutableArray *d4=[[NSMutableArray alloc]initWithArray:[[d3 reverseObjectEnumerator]allObjects]];
// NSArray *d4=[[d3 reverseObjectEnumerator]allObjects];
NSLog(@"倒序%@",d4);
//添加
NSLog(@"------添加----------");
[d3 addObject:@"ikj"];
// 指定的位置 [d3 insertObject:@"wser" atIndex:[i+1]]
//删除
NSLog(@"-------删除---------");
[d3 removeObject:@"dda"];
// [d3 removeObjectAtIndex:2];
// [d3 removeLastObject];
//显示指定位置
NSString *abc=[d3 objectAtIndex:0];
NSLog(@"%@",abc);
//一次性显示
NSLog(@"-------一次性显示---------");
NSLog(@"%@\n\n",d3);
//循环显示
NSLog(@"-------循环显示---------");
for(NSString *f in d3)
{
NSLog(@"%@",f);
}
NSLog(@"\n\n");
//动态数组2
NSLog(@"------动态数组2----------");
NSMutableArray *p=[[NSMutableArray alloc]initWithCapacity:5];
[p addObject:@"5"];
[p addObject:@"8"];
[p addObject:@"2"];
[p addObject:@"1"];
[p addObject:@"9"];
for(int i=0;i<[p count];i++)
{
NSLog(@"数值%@",p[i]);
}
NSArray *p1=@[@"5",@"8",@"2",@"4",@"9"];
//正序排列
NSLog(@"--------正序排列--------");
//小到大
p1=[p1 sortedArrayUsingComparator:^NSComparisonResult(id p2, id p3)
{
NSComparisonResult p4=[p2 compare:p3];
return p4==NSOrderedDescending;
}];
for(int i=0;i<[p1 count];i++)
{
NSLog(@"sdad%@",p1[i]);
}
//大到小
NSLog(@"\n-------------");
NSComparator pp1=^(id mm1,id mm2)
{
return [mm2 compare:mm1];
};
NSArray *pp2=[p1 sortedArrayUsingComparator:pp1];
for(int i=0;i<[pp2 count];i++)
{
NSLog(@"sdad%@",pp2[i]);
}
//小到大
NSArray *p21=@[@"5",@"8",@"2",@"4",@"9"];
NSArray *p22=[p21 sortedArrayUsingSelector:@selector(compare:)];
NSLog(@"小到大%@",p22);
//倒序排列
NSLog(@"------降序排列----------");
//大到小
// p1=[p1 sortedArrayUsingComparator:^NSComparisonResult(id p2, id p3)
// {
// NSComparisonResult p4=[p2 compare:p3];
// return p4==NSOrderedAscending;
// }];
//降序排列
NSArray *p31=[NSArray arrayWithObjects:@"6",@"7",@"2", nil];
NSArray *p11=[p31 sortedArrayUsingSelector:@selector(class)];
NSLog(@"降序排列%@",p11);
for(int i=0;i<[p11 count];i++)
{
NSLog(@"%@",p11[i]);
}
//取值
NSLog(@"-------取值---------");
//从0开始
NSString *s = [p31 objectAtIndex:2];
NSLog(@"%@\n\n",s);
//大小排序
NSLog(@"-------小到大排序---------");
NSMutableArray *d7=[[NSMutableArray alloc]initWithObjects:@"2",@"7",@"5",@"8",nil];
NSArray *d8=[d7 sortedArrayUsingSelector:@selector(compare:)];
//循环方法1 count元素个数
for(int i=0;i<[d8 count];i++)
{
NSLog(@"%@",d8[i]);
}
NSLog(@"--方法2--");
//循环方法2
for(NSString *d9 in d8)
{
NSLog(@"%@",d9);
}
//循环方法3
NSLog(@"--方法3--");
for(id d21 in d8)
{
NSLog(@"%@",d21);
}
NSLog(@"\n\n");
//降序排序
NSLog(@"-------降序排序---------");
NSArray *d9=[[d7 reverseObjectEnumerator]allObjects];
for(NSString *d10 in d9)
{
NSLog(@"%@",d10);
}
NSLog(@"\n\n");
/////不可变字典
NSLog(@"-------不可变字典---------");
//前值 后钥匙
NSLog(@"------前值 后钥匙----------");
NSDictionary *h=[NSDictionary dictionaryWithObjectsAndKeys:@"kk",@"1",@"pp",@"2",@"oi",@"3",nil];
//后值 前钥匙
NSLog(@"-------后值 前钥匙---------");
NSDictionary *h1=@{@"1":@"ff",@"2":@"dd",@"3":@"yy"};
//选择钥匙对应值
NSLog(@"-------选择钥匙对应值---------");
NSString *i1=[h objectForKey:@"2"];
NSLog(@"选择钥匙对应的值%@",i1);
NSLog(@"\n\n");
//选择所有钥匙
NSLog(@"-------选择所有钥匙---------");
NSArray *ii1=[h allKeys];
for(id io1 in ii1)
{
NSLog(@"%@",io1);
}
//2
NSEnumerator *i2=[h keyEnumerator];
for(NSString *i3 in i2)
{
NSLog(@"钥匙%@",i3);
}
NSLog(@"\n\n");
//选择所有的值
NSLog(@"------选择所有的值----------");
NSArray *ii2=[h allValues];
for(id io2 in ii2)
{
NSLog(@"%@",io2);
}
//2
NSEnumerator*i4=[h objectEnumerator];
for(NSString *i5 in i4)
{
NSLog(@"值%@",i5);
}
NSLog(@"\n\n");
//输出所有对应的值
NSLog(@"-------输出所有对应的值--------");
for(NSString *i6 in h)
{
NSLog(@"钥匙%@对应的值为%@",i6,[h objectForKey:i6]);
}
NSLog(@"\n\n");
//转为数组
NSLog(@"------转为数组----------");
NSArray *h2=[h allValues];
NSLog(@"数组为%@",h2);
NSArray *h3=[h1 allValues];
NSLog(@"数组为%@",h3);
//正序排序
NSLog(@"-------正序排序---------");
h2=[h2 sortedArrayUsingComparator:^NSComparisonResult(id h4, id h5)
{
NSComparisonResult h6=[h4 compare:h5];
return h6==NSOrderedDescending;
}];
NSLog(@"正序排序%@",h2);
/////可变字典
NSLog(@"-------可变字典---------");
NSDictionary *j=[NSDictionary dictionaryWithObjectsAndKeys:@"u23u",@"1",@"fre",@"2",@"eeoi",@"3",nil];
NSMutableDictionary *j1=[NSMutableDictionary dictionaryWithDictionary:j];
//增加
NSLog(@"---------增加-------");
[j1 setObject:@"hsja" forKey:@"4"];
for(id k in j1)
{
NSLog(@"增加后%@,%@",k,[j1 objectForKey:k]);
}
NSLog(@"\n");
//2
NSDictionary *jj1=[NSDictionary dictionaryWithObject:@"ppe" forKey:@"5"];
[j1 addEntriesFromDictionary:jj1];
NSLog(@"%@",j1);
//删除
NSLog(@"-------删除---------");
[j1 removeObjectForKey:@"1"];
for(id k in j1)
{
NSLog(@"删除后%@,%@",k,[j1 objectForKey:k]);
}
NSLog(@"\n");
//2
NSArray *kk1=[NSArray arrayWithObjects:@"3",@"4", nil];
[j1 removeObjectsForKeys:kk1];
for(id k in j1)
{
NSLog(@"删除后%@,%@",k,[j1 objectForKey:k]);
}
//字典排序1升序 2降序
NSLog(@"-------字典排序1升序 2降序---------");
NSMutableDictionary *dd1=[NSMutableDictionary dictionaryWithDictionary:@{@"name":@"赵本山",@"age":@"67",@"sex":@"nan"}];
NSMutableDictionary *dd6=[NSMutableDictionary dictionaryWithDictionary:@{@"name":@"张国荣",@"age":@"39",@"sex":@"nan"}];
NSMutableDictionary *dd7=[NSMutableDictionary dictionaryWithDictionary:@{@"name":@"刘晓庆",@"age":@"25",@"sex":@"wu"}];
NSMutableArray *ff=[[NSMutableArray alloc]initWithArray:@[dd1,dd6,dd7]];
NSArray *fff=[dd1 allValues];
NSMutableDictionary *po=[NSMutableDictionary dictionaryWithDictionary:@{@"name":@"赵本山",@"age":@"67",@"sex":@"nan"}];
//替换
[po setDictionary:@{@"name":@"张国荣",@"age":@"39",@"sex":@"nan"}];
for(id k in po)
{
NSLog(@"%@ = %@",k,[po objectForKey:k]);
}
NSLog(@"------");
//快速遍历
for(id k in fff)
{
NSLog(@"%@",k);
}
NSLog(@"------");
//枚举遍历
NSLog(@"\n");
NSEnumerator *ll1=[dd6 keyEnumerator];
id ll2;
while (ll2) {
id k=[dd6 objectForKey:ll2];
NSLog(@"%@",k);
ll2=[ll1 nextObject];
}
NSLog(@"\n-----");
//修改
NSLog(@"\n-------修改------\n");
for(int i=0;i<[ff count];i++)
{
if([ff[i][@"sex"] compare:@"wu"]==0)
{
ff[i][@"sex"]=@"ff";ff[i][@"name" ]=@"范冰冰";
}
}
for(int i=0;i<[ff count];i++)
{
NSMutableDictionary *ff2=[NSMutableDictionary dictionaryWithDictionary:ff[i]];
NSLog(@"%@ %@ %@",ff2[@"name" ],ff2[@"age"] ,ff2[@"sex"]);
}
NSLog(@"\n-------遍历------\n");
for(int i=0;i<[ff count];i++)
{
NSMutableDictionary *ff2=[NSMutableDictionary dictionaryWithDictionary:ff[i]];
NSLog(@"名字:%@ 年龄:%@ 性别:%@",ff2[@"name" ],ff2[@"age"] ,ff2[@"sex"]);
}
NSLog(@"----ssss---\n");
for(NSDictionary *fb in ff)
{
NSLog(@"名字:%@ 年龄:%@ 性别:%@",fb[@"name" ],fb[@"age"] ,fb[@"sex"]);
}
////集合
NSLog(@"\n\n---------集合-------");
NSSet *k1=[NSSet setWithObjects:@"1",@"2",nil];
for(NSString *k2 in k1)
{
NSLog(@"%@",k2);
}
if([k1 containsObject:@"1"]==YES)
{
NSLog(@"chenggong");
}
////可变集合
NSLog(@"-------可变集合---------");
NSMutableSet *k3=[NSMutableSet setWithSet:k1];
//添加
NSLog(@"-------添加---------");
[k3 addObject:@"5"];
NSLog(@"增加%@",k3);
//删除
NSLog(@"-------删除---------");
[k3 removeObject:@"2"];
NSLog(@"删除%@",k3);
//交集
NSLog(@"--------交集--------");
NSLog(@"%@---%@\n----",k1,k3);
[k3 intersectsSet:k1];
NSLog(@"交集%@",k3);
NSLog(@"交集%@",k1);
//并集
NSLog(@"--------并集--------");
[k3 unionSet:k1];
NSLog(@"并集%@",k3);
NSLog(@"并集%@",k1);
//求合集指定的值的个数
NSLog(@"-------求合集指定的值的个数---------");
NSCountedSet *k4=[NSCountedSet setWithSet:k3];
[k4 addObject:@"3"];
[k4 addObject:@"5"];
[k4 addObject:@"7"];
NSLog(@"%ld",[k4 countForObject:@"2"]);
NSInteger kk=[k4 count];
NSLog(@"%ld\n------",kk);
NSArray *kk2=[NSArray arrayWithObjects:@"i",@"h",@"o", nil];
NSSet *kk3=[[NSSet alloc]initWithArray:kk2];
NSLog(@"%@\n------",kk3);
NSMutableSet *n1=[NSMutableSet setWithObjects:@"1",@"5",@"7",@"3", nil];
NSMutableSet *n2=[NSMutableSet setWithObjects:@"2",@"5",@"6",@"3", nil];
//n1去掉n2里相同的值 交集
[n1 minusSet:n2];
NSLog(@"%@",n1);
NSLog(@"%@",n2);
NSLog(@"-----===");
[n1 intersectsSet:n2];
NSLog(@"%@",n1);
NSLog(@"%@",n2);
//字典转数组
NSArray *bb=@[
@{@"name":@"tom",@"age":@"54",@"id":@"1001"},
@{@"name":@"ggf",@"age":@"22",@"id":@"1002"},
@{@"name":@"rew",@"age":@"65",@"id":@"1003"},
];
NSMutableArray *bb1=[[NSMutableArray alloc]initWithObjects:bb, nil];
for(int i=0;i<[bb1 count];i++)
{
NSDictionary *aa=bb1[i];
NSLog(@"%@",aa);
}
//字符串变成数组
NSLog(@"---------字符串变成数组-------");
NSString *j5=@"dsa,iua,gtrf,ouui.yri";
NSArray *j6=[j5 componentsSeparatedByString:@","];
NSLog(@"数组%@",j6);
for(NSString *f11 in j6)
{
NSLog(@"数值%@",f11);
}
NSLog(@"\n\n");
//数组变成字符串
NSLog(@"--------数组变成字符串--------");
NSString *j7=[j6 componentsJoinedByString:@""];
NSLog(@"字符串%@",j7);
}
return 0;
}
浙公网安备 33010602011771号