zoukankan      html  css  js  c++  java
  • NSString之Format

    三点用法总结:

    1. 类型转换:基本类型到对象类型
      1. 需要调用NSString的fotmat方法
      2. NSString  *location = [NSString  stringWithFormat:@"location = %i ,2];
    2. 连续定义
      1. 字符串接字符串,或者基本类型的转换(红色的下面是橙色)
      2. NSString *color = [NSString stringWithFormat:@"Red under is %@,location = %i",@"Orange",2];

       3.  通过占位符为变量名进行占位,对变量名内的数据进行格式化

          1.NSString *str = @"color"; unichar ch = [str characterAtIndex:3]; NSLog(@"index:%c",ch);

          2. 使用可变对象一定要先初始化(NSMutableString可以直接使用Format,添加也可以使用Format进行格式化)

            1.NSMutableString * str_M = [NSMutableString  stringWithFormat:@""];

            2.%@:对对象类型数据进行占位,即使这个数据是存储于变量中的对象

                         3.[str_M appendFormat:@"%@=%@", str, dic[str]];//把字典的key和value连接起来

      

    // 不但可以通过占位符来对字符串进行连续定义

            unichar ch = 'Y';

            NSLog(@"%@", [NSString stringWithFormat:@"%c", ch]); //还可以对变量内数据进行Format操作

            color = [NSString stringWithFormat:@"Red under is %@,location = %d",@"Orange",2];

            NSLog(@"占位符自定义:%@",color);

  • 相关阅读:
    转载 消灭程序员需要百年吗?(重要参考)
    转载的一篇,代码规范
    自改的删除数据库中所有外键语句
    [转]批量禁用外键后,清空表数据
    我的分组分页查询语句
    Yii 分页方法总结
    25个Apache性能优化技巧推荐
    浅谈MindSpore的动态Shape
    C++开发总结 A
    Linux环境下开发常用命令汇总 A
  • 原文地址:https://www.cnblogs.com/pruple/p/5235932.html
Copyright © 2011-2022 走看看