objective-c常见类型%z
来源:互联网 发布:数据库管理员教程 编辑:程序博客网 时间:2024/06/05 17:24
常用的一些占位符:
%@:字符串占位符
%d:整型
%ld:长整型
%f:浮点型
%c:char类型
%%:%的占位符
尽管有那么多的占位符,但是好像没有发现BOOL型的数据的占位符,这也是比较纠结的地方,看了一下别人是怎么解决这个问题的
BOOL studyBool = YES; NSLog(@"打印BOOL型数据%@",studyBool?@"YES":@"NO");//打印BOOL型数据YES NSLog(@"打印BOOL型数据%d",studyBool);//打印BOOL型数据1 BOOL alsoBool = NO; NSLog(@"打印BOOL型数据%@",alsoBool?@"YES":@"NO");//打印BOOL型数据NO NSLog(@"打印BOOL型数据%d",alsoBool);//打印BOOL型数据0
详细介绍:**********************************************************
%@: Objective-C对象,印有字符串返回descriptionWithLocale:如果于的话,或描述相反.CFTypeRef工作对象,返回的结果的CFCopyDescription功能.(这个翻译有问题建议按照自己的理解方式理解)。
%%: 为'%'字符;
%d,%D,%i: 为32位整型数(int);
%u,%U: 为32位无符号整型数(unsigned int);
%hi: 为有符号的16位整型数(short);
%hu: 为无符号的16位整型数(unsigned shord);
%qi: 为有符号的64位整型数(long long);
%qu: 为无符号的64位整型数(unsigned long long);
%x: 为32位的无符号整型数(unsigned int),打印使用数字0-9的十六进制,小写a-f;
%X: 为32位的无符号整型数(unsigned int),打印使用数字0-9的十六进制,大写A-F;
%qx: 为无符号64位整数(unsigned long long),打印使用数字0-9的十六进制,小写a-f;
%qX: 为无符号64位整数(unsigned long long),打印使用数字0-9的十六进制,大写A-F;
%o,%O: 为32位的无符号整数(unsigned int),打印八进制数;
%f: 为64位的浮点数(double);
%e: 为64位的浮点数(double),打印使用小写字母e,科学计数法介绍了指数的增大而减小;
%E: 为64位的浮点数(double),打印科学符号使用一个大写E介绍指数的增大而减小;
%g: 为64位的浮点数(double),用%e的方式打印指数,如果指数小于4或者大于等于精度,那么%f的风格就会有不同体现;
%G: 为64位的浮点数(double),用%E的方式打印指数,如果指数小于4或者大于等于精度,那么%f的风格就会有不同体现;
%c: 为8位的无符号字符%c(unsigned char),通过打印NSLog()将其作为一个ASCII字符,或者,不是一个ASCII字符,八进制格式\ddd或统一标准的字符编码的十六进制格式\udddd,在这里d是一个数字;
%C: 为16位Unicode字符%C(unichar),通过打印NSLog()将其作为一个ASCII字符,或者,不是一个ASCII字符,八进制格式\ddd或统一标准的字符编码的十六进制格式\\udddd,在这里d是一个数字;
%s: 对于无符号字符数组空终止,%s系统中解释其输入编码,而不是别的,如utf-8;
%S: 空终止一系列的16位Unicode字符;
%p: 空指针(无效*),打印十六进制的数字0-9和小写a-f,前缀为0x;
%L: 在明确规定的长度下,进行修正,下面的一批数据a,A,e,E,f,F,g,G应用于双精度长整型的参数;
%a: 为64位的浮点数(double),按照科学计数法打印采用0x和一个十六进制数字前使用小写小数点p来介绍指数的增大而减小;
%A: 为64位的浮点数(double),按照科学计数法打印采用0X和一个十六进制数字前使用大写字母小数点P界扫指数的增大而减小;
%F: 为64位的浮点数(double),按照十进制表示法进行打印;
%z: 修改说明在%z长度以下d,i,o,u,x,X适用于某一指定类型的转换或者适用于一定尺寸的整数类型的参数;
%t: 修改说明在%t长度以下d,i,o,u,x,X适用于某一指定类型或一定尺寸的整数类型的转换的参数;
%j: 修改说明在%j长度以下d,i,o,u,x,X适用于某一指定类型或一定尺寸的整数类型的转换的参数。
英文文档
格式定义
The format specifiers supported by the NSString formatting methods and CFString formatting functions follow the IEEE printf specification; the specifiers are summarized in Table 1. Note that you can also use the “n$” positional specifiers such as %1$@ %2$s. For more details, see the IEEE printf specification. You can also use these format specifiers with the NSLog function.
平台依赖
Mac OS X uses several data types—NSInteger, NSUInteger,CGFloat, and CFIndex—to provide a consistent means of representing values in 32- and 64-bit environments. In a 32-bit environment, NSInteger and NSUInteger are defined as int and unsigned int, respectively. In 64-bit environments, NSInteger and NSUInteger are defined as long and unsigned long, respectively. To avoid the need to use different printf-style type specifiers depending on the platform, you can use the specifiers shown in Table 2. Note that in some cases you may have to cast the value.
The following example illustrates the use of %ld to format an NSInteger and the use of a cast.
2
printf("%ld\n",
In addition to the considerations mentioned in Table 2, there is one extra case with scanning: you must distinguish the types for float and double. You should use %f for float, %lf for double. If you need to use scanf (or a variant thereof) with CGFloat, switch to double instead, and copy the double to CGFloat.
2
3
4
double
sscanf
imageWidth
It is important to remember that %lf does not represent CGFloat correctly on either 32- or 64-bit platforms. This is unlike %ld, which works for long in all cases.
- objective-c常见类型%z
- Objective-c 枚举类型
- objective-c 类型转换
- objective-c类型转换
- [Objective-C] BOOL类型
- Objective-C类型推断
- Objective-c:集合类型
- Objective-C 类型编码
- Objective-C id类型
- objective-c C类型数组
- Objective-C runtime常见用法
- Objective-C数量类型-Objective-C int 整数类型
- Objective-C数量类型-Objective-C float 浮点类型
- Objective-C数量类型-Objective-C double 双精度类型
- Objective-C数量类型-Objective-C char 字符类型
- Objective-C数量类型-Objective-C float 浮点类型
- Objective-C数量类型-Objective-C int 整数类型
- Objective-C 定义的类型
- 高效解析json例子,Jackson框架
- .net 已安装的插件卸载方法
- 为什么 iOS 开发中,xib跟storyboard拖得控件一般为 weak 而不是 strong
- 【Web前端】:对前端开发模式的思考
- 【angularJs】--入门实例二
- objective-c常见类型%z
- GHOST 误操作的恢复方法
- hibernate延迟加载(get和load的区别)
- Eclipse安装应知应会
- 在程序中启动另一个程序
- 分析定位占用CPU资源高的JVM线程
- C# Window编程随记——运行时动态对象创建和动态方法调用
- Java内存模型总结
- 路数有限制(w的倍数)的最短路,【二维dijkstra】 双重限制并输出路径和方法数