zoukankan      html  css  js  c++  java
  • oc程序代码

    //

    //  main.m

    //  aa

    //

    //  Created by rcfwzx on 15/11/20.

    //  Copyright (c) 2015年 rcfwzx. All rights reserved.

    //

    #import <Foundation/Foundation.h>

    int main(int argc, const char * argv[]) {

        @autoreleasepool {

           NSString *a=@"jjkkllFDSFDaqt";

            NSString *b=@"atrGDSass";

            //拼接

            NSLog(@"--------拼接--------");

            NSString *c=[a stringByAppendingString:b];

            NSLog(@"拼接%@",c);

            NSLog(@"拼接为%@ ",[a stringByAppendingString:b]);

            //赋值

            NSLog(@"--------赋值--------");

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

            e=@"fflls";

            NSLog(@"负值为%@ ",e);

            //格式化

            NSLog(@"-------格式化---------");

            NSString *c1=[[NSString alloc]initWithString:[NSString stringWithFormat:@"%@",c]];

            NSLog(@"%@ ",c1);

            //判断是否相等

            NSLog(@"------判断是否相等----------");

            BOOL *c2=[a isEqualToString:b];

            if(c2==0)

            NSLog(@"不相等 ");

            else  NSLog(@"相等 ");

            NSLog(@"判断为%i ",[a isEqualToString:b]);

            //大写

            NSLog(@"--------大写--------");

            NSLog(@"大写%@",[a uppercaseString]);

            //小写

            NSLog(@"-------小写---------");

            NSLog(@"小写%@",[a lowercaseString]);

            //首字母大写

            NSLog(@"-------首字母大写---------");

            NSLog(@"首字母%@ ",[c capitalizedString]);

            //长度

            NSLog(@"-------长度---------");

            unsigned long a1=[a length];

            NSLog(@"字符%@的长度为%d ",a,a1);

            //从输入的数字后面开始到尾 显示

            NSLog(@"------从输入的数字后面开始到尾 显示----------");

            NSString *c4=[a substringFromIndex:4];

            NSLog(@"%@ ",c4);

            //从开始到输入的数字为止 显示

            NSLog(@"-------从开始到输入的数字为止 显示---------");

            NSString *c5=[a substringToIndex:5];

            NSLog(@"%@ ",c5);

            //从输入的第一个数字后面开始 显示第二数字的数量为止

            NSLog(@"---------从输入的第一个数字后面开始 显示第二数字的数量为止-------");

            NSString *c7=[a substringWithRange:NSMakeRange(4,3)];

            NSLog(@"%@ ",c7);

            //不可变字符串

            NSLog(@"--------不可变字符串--------");

            NSString *c8=@"dsopliktkkgrt";

            //可变字符串

            NSLog(@"---------可变字符串-------");

            NSMutableString *c9=[[NSMutableString alloc]initWithString:c8];

            NSLog(@"可变字符串为%@ ",c9);

            //插入字符串到另一个字符串

            NSLog(@"--------插入字符串到另一个字符串--------");

            [c9 insertString:@"ppl" atIndex:3];

            NSLog(@"可变字符串为%@ ",c9);

            //查看

            NSLog(@"---------查看-------");

            NSRange sub=[c9 rangeOfString:@"k"];

            NSLog(@"查看%@ ",c9);

            while (sub.location!=NSNotFound)

            {

                [c9 deleteCharactersInRange:sub];

                sub=[c9 rangeOfString:@"k"];

            }

            if(sub.location!=NSNotFound)

            {

                NSLog(@"没找到 ");

            }

            //删除

            NSLog(@"-------删除---------");

            NSLog(@"删除%@ ",c9);

            //重新设置字符串

            NSLog(@"-------重新设置字符串---------");

            [c9 setString:@"kkggpqwe"];

            //替换/修改

            NSLog(@"--------替换/修改--------");

            [c9 replaceCharactersInRange:NSMakeRange(5,3) withString:@"k"];

            NSLog(@"替换%@ ",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"];

            //一次性显示

            NSLog(@"-------一次性显示---------");

            NSLog(@"%@ ",d3);

            //循环显示

            NSLog(@"-------循环显示---------");

            for(NSString *f in d3)

            {

                NSLog(@"%@",f);

            }

            NSLog(@" ");

            

           //动态数组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;

                }];

            NSLog(@"正序排序%@",p1);

            //倒序排列

            NSLog(@"------倒序排列----------");

            p1=[p1 sortedArrayUsingComparator:^NSComparisonResult(id p2, id p3)

               {

                   NSComparisonResult p4=[p2 compare:p3];

                   return p4==NSOrderedAscending;

               }];

            NSLog(@"倒序排列%@",p1);

            //取值

            NSLog(@"-------取值---------");

            NSString *s = [p objectAtIndex:1];

            NSLog(@"%@ ",s);

            

            //排序

            NSLog(@"-------排序---------");

            NSMutableArray *d7=[[NSMutableArray alloc]initWithObjects:@"2",@"7",@"5",@"8",nil];

            NSArray *d8=[d7 sortedArrayUsingSelector:@selector(compare:)];

            for(int i=0;i<[d8 count];i++)

            {

                NSLog(@"%@",d8[i]);

            }

            //

            for(NSString *d9 in d8)

            {

                NSLog(@"%@",d9);

            }

            NSLog(@" ");

            NSArray *d9=[[d7 reverseObjectEnumerator]allObjects];

            for(NSString *d10 in d9)

            {

                NSLog(@"%@",d10);

            }

            NSLog(@" ");

            

            /////不可变字典

            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(@" ");

            //选择所有钥匙

            NSLog(@"-------选择所有钥匙---------");

            NSEnumerator *i2=[h keyEnumerator];

            for(NSString *i3 in i2)

            {

                NSLog(@"钥匙%@",i3);

            }

            NSLog(@" ");

            //选择所有的值

            NSLog(@"------选择所有的值----------");

            NSEnumerator*i4=[h objectEnumerator];

            for(NSString *i5 in i4)

            {

                NSLog(@"值%@",i5);

            }

            NSLog(@" ");

            //输出所有对应的值

            NSLog(@"-------输出所有对应的值--------");

            for(NSString *i6 in h)

            {

                NSLog(@"钥匙%@对应的值为%@",i6,[h objectForKey:i6]);

            }

            NSLog(@" ");

            //转为数组

            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(NSString *k in j1)

            {

                NSLog(@"增加后%@,%@",k,[j1 objectForKey:k]);

            }

            NSLog(@" ");

            //删除

            NSLog(@"-------删除---------");

            [j1 removeObjectForKey:@"1"];

            for(NSString *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]];

    //        NSMutableArray *ff=[[NSMutableArray alloc]initWithArray:@[@{@"name":@"liu",@"age":@"67",@"sex":@"nan"},

    //                             @{@"name":@"zhang",@"age":@"79",@"sex":@"nan"},

    //                             @{@"name":@"ahou",@"age":@"56",@"sex":@"wu"}

    //                             ]];

            NSSortDescriptor *ff1=[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:0];

            for(int i=0;i<[ff count];i++)

            {

                if([ff[i][@"sex"] compare:@"wu"]==0)

                {

                    ff[i][@"sex"]=@"ff";ff[i][@"name" ]=@"范冰冰";

    //                [ff[i] setObject:@"shhg" forKey:@"sex"];

                    

                }

            }

            

            NSArray *pp=[ff sortedArrayUsingDescriptors:[NSArray arrayWithObjects:ff1, nil]];

            for(int i=0;i<[pp count];i++)

            {

                NSMutableDictionary *ff2=[NSMutableDictionary dictionaryWithDictionary:pp[i]];

                NSLog(@"%@  %@  %@",ff2[@"name" ],ff2[@"age"] ,ff2[@"sex"]);

            }

            NSLog(@" -------遍历------ ");

            for(int i=0;i<[pp count];i++)

            {

                NSMutableDictionary *ff2=[NSMutableDictionary dictionaryWithDictionary:pp[i]];

            [ff2 enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {

                NSLog(@"%@ %@", key, obj);

            }];

            }

            ////集合

            NSLog(@" ---------集合-------");

            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(@"--------交集--------");

            [k1 intersectsSet:k3];

            NSLog(@"交集%@",k3);

            //并集

            NSLog(@"--------并集--------");

            [k3 unionSet:k1];

            NSLog(@"并集%@",k3);

            //求合集指定的值的个数

            NSLog(@"-------求合集指定的值的个数---------");

            NSCountedSet *k4=[NSCountedSet setWithSet:k3];

            [k4 addObject:@"3"];

            [k4 addObject:@"5"];

            [k4 addObject:@"7"];

            NSLog(@"%ld",[k4 countForObject:@"2"]);

            //字典转数组

            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(@" ");

            //数组变成字符串

            NSLog(@"--------数组变成字符串--------");

            NSString *j7=[j6 componentsJoinedByString:@","];

            NSLog(@"字符串%@",j7);

            //排序

            //自定义数组

            

    //        //123-456-789找到并且删除变成123456789   并且替换成" ";

    //        //将字符串159和39,变成十进制(int型),相差,用字符串输出

    //        NSMutableString *c11=[[NSMutableString alloc]init];

    //        c11=[NSMutableString stringWithFormat:@"123-456-789"];

    //        NSRange sub1=[c11 rangeOfString:@"-"];

    //        while (sub1.location!=NSNotFound)

    //        {

    //            [c11 deleteCharactersInRange:sub1];

    //            sub1=[c11 rangeOfString:@"-"];

    //        }

    //        NSLog(@"变成后%@ ",c11);

    //        

    //        NSString *a2=@"159",*b2=@"39";

    //        int a3=[a2 intValue];

    //        int b3=[b2 intValue];

    //        int b4=a3-b3;

    //        NSString *b5=[NSString stringWithFormat:@"%d",b4];

    //        NSLog(@"%@ ",b5);

    //        

    //        NSString *p=@"wo yao chi fan";

    //        NSLog(@"请找出chi并显示长度 ");

    //        NSRange sub3=[p rangeOfString:@"chi"];

    //        if(sub3.location!=NSNotFound)

    //        {

    //            NSLog(@"chi以找到");

    //        }

    ////        unsigned long l=[p length];

    //        NSLog(@"chi的长度为%ld",sub3.location);

            

            

            

            

        }

        return 0;

    }

  • 相关阅读:
    HTML meta viewport属性说明(mark)
    利用css样式画各种图形初步、进阶、高级(一)
    sql where 1=1和 0=1 的作用
    java日志文件log4j.properties配置详解
    VB面向对象编程
    怎么上传代码?
    Spring中部署Activiti流程定义的三种姿势
    不会使用Spring的配置文件,赶紧把这个甩给他
    一起玩转玩转LiteOS组件:Opus
    带你读AI论文丨RAID2020 Cyber Threat Intelligence Modeling GCN
  • 原文地址:https://www.cnblogs.com/bobohahaha/p/5120779.html
Copyright © 2011-2022 走看看