• ios字符串截取/数据存入数组


     
    
    #import <Foundation/Foundation.h>
    
     
    
    int main(int argc, const char * argv[]) {
    
        @autoreleasepool {
    
    //1.对字符串“2015-09-01 08:19:10”操作,输出"08:19:10"。要求使用两种截取方式。
    
            //第一个
    
            NSString *str=@"2015-09-01 08:19:10";
    
            NSRange range1=[str rangeOfString:@"08:19:10"];
    
            NSString *subStr=[str substringWithRange:range1];
    
            NSLog(@"第一题-------(1)");
    
            NSLog(@"%@",subStr);
    
            NSString *substr1=[str substringFromIndex:range1.location];
    
            NSLog(@"第一题-------(2)");
    
            NSLog(@"%@",substr1);
    
            
    
            
    
            
    
            
    
    /*2.数组中存取以下数据:
    
      @[@{@"name":@"陈丰",@"age":@"32"},
    
        @{@"name":@"孙明",@"age":@"24"},
    
        @{@"name":@"王明",@"age":@"12"},
    
        @{@"name":@"李西",@"age":@"50"}
    
       ]
    
         1)按年龄进行排序(降序),输出数据
    
         2)删除“陈丰”并输出数据
    
     */
    
            
    
            NSDictionary *dic1=@{@"name":@"陈丰",@"age":@"32"};
    
            NSDictionary *dic2=@{@"name":@"孙明",@"age":@"24"};
    
            NSDictionary *dic3=@{@"name":@"王明",@"age":@"12"};
    
            NSDictionary *dic4=@{@"name":@"李西",@"age":@"50"};
    
            NSMutableArray *arr=[[NSMutableArray alloc]initWithObjects:dic1,dic2,dic3,dic4,nil];
    
            NSSortDescriptor *sorts=[[NSSortDescriptor alloc]initWithKey:@"age" ascending:YES];
    
            [arr sortUsingDescriptors:[NSArray arrayWithObjects:sorts, nil]];
    
            NSLog(@"第二题-------(1)");
    
            NSLog(@"排序后-------(升序)");
    
            for(NSDictionary *dic in arr){
    
     
    
                NSLog(@"%@,%@",[dic objectForKey:@"name"],[dic objectForKey:@"age"]);
    
            }
    
            NSLog(@"排序后-------(降序)");
    
            NSSortDescriptor *sorts1=[[NSSortDescriptor alloc]initWithKey:@"age" ascending:NO];
    
            [arr sortUsingDescriptors:[NSArray arrayWithObjects:sorts1, nil]];
    
            for(NSDictionary *dic in arr){
    
                NSLog(@"%@ %@",dic[@"name"],dic[@"age"]);
    
            }
    
            NSLog(@"第二题-------(2)");
    
            for(int i=0;i<[arr count];i++){
    
                NSDictionary *dic=arr[i];
    
                if([dic[@"name"] isEqual:@"陈丰"]){
    
                    [arr removeObject:dic];
    
                }
    
            }
    
            for(NSDictionary *dic in arr){
    
                NSLog(@"%@ %@",dic[@"name"],dic[@"age"]);
    
            }
    
        
    
            
    
        }
    
        return 0;
    
    }
  • 相关阅读:
    js获取当前日期
    Mysql错误1452
    数字输入框禁止输入字母
    laravel关联外键报错
    golang for range channel
    golang实现简单哈希表(拉链法解决冲突)
    K个一组反转链表(golang)
    golang 少见的语法问题(无用)
    golang实现循环队列
    数组中连续序列和最大值(循环数组)
  • 原文地址:https://www.cnblogs.com/jun1994/p/5116216.html
Copyright © 2020-2023  润新知