爱咋za吧 关注:4贴子:212
  • 13回复贴,共1
IP属地:辽宁1楼2015-03-26 21:53回复
    取子串 substring
    NSString *str4 = @"iPhone6Plus";
    fromIndex(从中间往后)
    NSString *str5 = [str4 substringFromIndex:5];
    toIndex(从头到中间)
    NSString *str6 = [str4 substringToIndex:6];
    withRange(从哪开始 到第几个 需要定义结构体)
    NSRange r = NSMakeRange(6, 1);
    NSString *str7 = [str4 substringWithRange:NSMakeRange(6, 1)];
    判断前缀/后缀
    if ([str4 hasPrefix:@"iPh"]) {
    NSLog(@"有该前缀");
    }
    if ([str4 hasSuffix:@"Plus"]) {
    NSLog(@"有该后缀");
    }
    字符串 万能转换公式
    stringWithFormat
    NSString *str4 = [NSString stringWithFormat:@"I have %@%d%@", str1, 6, str3];
    //拼接方法
    NSString *str5 = [str1 stringByAppendingString:str2];
    //替换方法
    NSString *str6 = [str5 stringByReplacingOccurrencesOfString:@"Plus" withString:@"s"];
    //相等
    if ([str6 isEqualToString:str7]) {
    NSLog(@"两个字符串内容相同")
    }
    //字符串比较
    NSString *str1 = @"iPhone6Plus";
    NSString *str2 = @"iPhone7";
    NSComparisonResult r = [str1 compare:str2];
    if (r == NSOrderedAscending) {
    NSLog(@"升序");
    }
    else if (r == NSOrderedDescending)
    {
    NSLog(@"降序");
    }
    else if (r == NSOrderedSame)
    {
    NSLog(@"相等");
    }
    /NSMutableString 可变字符串
    //创建之后 内容可以改变
    //可变数据类 一般初始化为空
    NSMutableString *mStr = [NSMutableString string];
    //拼接字符串
    [mStr appendString:@"DLS"];
    [mStr appendString:@"150303"];
    NSLog(@"%@", mStr);
    //插入
    [mStr insertString:@"lanou" atIndex:0];
    //删除(第几个开始到后面的第几个)
    [mStr deleteCharactersInRange:NSMakeRange(2, 2)];
    //NSArray 不可变数组
    //数组的创建
    NSArray *arr1 = [NSArray arrayWithObjects:@"iPhone", @"Android", @"WinPhone", @"中文", nil];
    //数组元素个数
    NSLog(@"count %ld", arr1.count);
    //通过下标获取相应位置的元素
    NSString *str = [arr1 objectAtIndex:3];
    for (NSInteger i = 0; i < arr1.count; i++) {
    NSLog(@"%@",[arr1 objectAtIndex:i]);
    }
    //NSMutableArray 可变数组
    NSMutableArray *mArr = [NSMutableArray array];
    //添加
    [mArr addObject:@"xiaoXiao"];
    [mArr addObject:@"jiLaoBan"];
    [mArr addObject:@"kangKang"];
    //插入
    [mArr insertObject:@"bigTree" atIndex:2];
    //替换
    [mArr replaceObjectAtIndex:0 withObject:@"suibian"];
    //交换
    [mArr exchangeObjectAtIndex:0 withObjectAtIndex:1];
    //删除
    [mArr removeObjectAtIndex:2];
    NSLog(@"%@", mArr);


    IP属地:辽宁2楼2015-04-01 20:50
    回复
      //NSDictionary 不可变字典
      //字典用来存放key-value(键值对)
      //key必须唯一 value必须是对象
      //字典是无需集合 所有的操作都通过key实现
      //但是创建的时候 value在前 Key在后
      //在字典中 value用 object表示
      /* NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:@"lilei", @"name", @"male", @"sex", nil];
      NSLog(@"%@", dic1);
      //所有key
      NSLog(@"%@", dic1.allKeys);
      //所有value
      NSLog(@"%@", dic1.allValues);
      //通过key值访问对应value objectForKey是字典访问
      NSLog(@"%@", [dic1 objectForKey:@"name"]);
      NSLog(@"-------------");
      //字典的遍历
      //1.得到key数组
      //2.遍历key数组 得到每一个key
      //3,通过key得到每一个value
      for (NSInteger i = 0; i < dic1.allKeys.count; i++) {
      NSString *p = [dic1.allKeys objectAtIndex:i];
      NSLog(@"%@ = %@", p, [dic1 objectForKey:p]);
      }
      */
      /* NSMutableDictionary *mDic = [NSMutableDictionary dictionary];
      //添加键值对
      //setObject:forKey: 字典方法
      //setValue:forKey: KVC方法
      //当key值不存在的时候 添加新的key-value对
      //当key存在时 找到对应key-value 修改对应的value值
      [mDic setObject:@"hanmeimei" forKey:@"name"];
      [mDic setObject:@"male" forKey:@"sex"];
      [mDic removeObjectForKey:@"sex"];
      NSLog(@"%@", mDic);
      */
      //练习
      //遍历可变字典
      //1.创建可变字典
      //2.添加key- value对 name sex age hobby
      //3.遍历
      /* NSMutableDictionary *mStr = [NSMutableDictionary dictionary];
      [mStr setObject:@"xiaoming" forKey:@"name"];
      [mStr setObject:@"male" forKey:@"sex"];
      [mStr setObject:@"20" forKey:@"age"];
      [mStr setObject:@"play" forKey:@"hobby"];
      for (NSInteger i = 0; i < mStr.allKeys.count; i++) {
      NSString *p = [mStr.allKeys objectAtIndex:i];
      NSLog(@"%@ %@", p, [mStr objectForKey:p]);
      }
      */
      //NSSet 不可变集合
      //无序 唯一 对象
      /* NSSet *set1 = [NSSet setWithObjects:@"a", @"p", @"p", @"l", @"l", @"e", nil];
      NSLog(@"%@", set1);
      //集合个数
      NSLog(@"%ld", set1.count);
      //获取某个元素
      NSLog(@"%@", [set1 anyObject]);
      //是否包含
      if ([set1 containsObject:@"p"]) {
      NSLog(@"包含");
      }
      //可变集合
      NSMutableSet *set2 = [NSMutableSet set];
      //添加
      [set2 addObject:@"c"];
      [set2 addObject:@"b"];
      [set2 addObject:@"a"];
      //删除
      [set2 removeObject:@"a"];
      NSLog(@"%@", set2);
      // NSCountedSet 计数集合
      NSCountedSet *cSet = [NSCountedSet setWithSet:set2];
      [cSet addObject:@"b"];
      NSLog(@"%@", cSet);
      //计数
      NSLog(@"count %ld", [cSet countForObject:@"b"]);
      */
      //快读枚举器 for-in
      //遍历数组 数组中每个元素
      /* NSArray *arr = [NSArray arrayWithObjects:@"1", @"3", @"3", nil];
      //获得从集合中得到的每一个元素
      for (NSArray *temp in arr) {
      NSLog(@"%@", temp);
      }
      //遍历字典 字典的key 通过key可以访问对应的value
      NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"lilei", @"name", @"male", @"sex", nil];
      for (NSString *key in dic) {
      NSLog(@"%@ %@", key, [dic objectForKey:key]);
      }
      */
      //数组排序
      NSArray *arr = [NSArray arrayWithObjects:@"kangKang", @"daShu", @"jiLaoBan", @"haoGe", @"xiaoQiang", @"xiaoMing", nil];
      NSLog(@"%@", arr);
      //方法选择器
      SEL s = @selector(compare:);
      NSArray *newArray = [arr sortedArrayUsingSelector:s];
      NSLog(@"%@", newArray);
      //可变数组的排序
      NSMutableArray *marr = [NSMutableArray arrayWithArray:arr];
      NSLog(@"%@", marr);
      [marr sortUsingSelector:@selector(compare:)];
      NSLog(@"%@", marr);


      IP属地:辽宁3楼2015-04-02 20:50
      回复
        IP属地:辽宁4楼2015-04-04 10:06
        回复
          NSString *path = @"/Users/dlios/Desktop/area.txt";
          NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
          NSArray *mStr = [str componentsSeparatedByString:@"\n"];
          NSMutableArray *province = [NSMutableArray array];
          for (NSString *s in mStr) {
          if (![s hasPrefix:@" "]) {
          NSMutableDictionary *pDic = [NSMutableDictionary dictionary];
          [pDic setObject:s forKey:@"name"];
          NSMutableArray *cArr = [NSMutableArray array];
          [pDic setObject:cArr forKey:@"city"];
          [province addObject:pDic];
          }
          else if ([s hasPrefix:@" "] && ![s hasPrefix:@" "])
          {
          NSMutableDictionary *cDic = [NSMutableDictionary dictionary];
          [cDic setObject:s forKey:@"name"];
          NSMutableArray *cArr = [NSMutableArray array];
          [cDic setObject:cArr forKey:@"zone"];
          NSMutableDictionary * pDic = [province lastObject];
          NSMutableArray *zArr = [pDic objectForKey:@"city"];
          [zArr addObject:cDic];
          }
          else if([s hasPrefix:@" "])
          {
          NSMutableDictionary *pDic = [province lastObject];
          NSMutableArray *cArr = [pDic objectForKey:@"city"];
          NSMutableDictionary *cDic = [cArr lastObject];
          NSMutableArray *zArr = [cDic objectForKey:@"zone"];
          [zArr addObject:s];
          }
          }
          NSLog(@"%@", province);


          IP属地:辽宁5楼2015-04-04 20:58
          回复
            http://www.cnbeta.com/articles/377401.htm


            IP属地:辽宁7楼2015-04-07 19:50
            回复
              f.lux


              IP属地:辽宁8楼2015-04-08 12:49
              回复
                尔等果如其母戏寡人欤


                IP属地:辽宁9楼2015-05-04 16:05
                回复
                  IP属地:辽宁10楼2015-05-04 20:19
                  回复
                    IP属地:辽宁11楼2015-05-21 17:06
                    回复
                      http://tool.oschina.net/codeformat/json


                      IP属地:辽宁12楼2015-05-21 17:07
                      回复
                        http://www.papertoilet.com/


                        IP属地:辽宁13楼2015-05-22 13:12
                        回复
                          IP属地:辽宁14楼2015-05-22 13:32
                          回复
                            http://hackertyper.net/


                            IP属地:辽宁15楼2015-05-25 13:49
                            回复