常用的一些占位符:

%@:字符串占位符

%d:整型

%ld:长整型

%f:浮点型

%c:char类型

%%:%的占位符

尽管有那么多的占位符,但是好像没有发现BOOL型的数据的占位符,这也是比较纠结的地方,看了一下别人是怎么解决这个问题的
[cpp] view plain copy
print? 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-; %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 . Note that you can also use the “n$” positional specifiers such as %$@ %$s. For more details, see the IEEE printf specification. You can also use these format specifiers with the NSLog function.
Table Format specifiers supported by the NSString formatting methods and CFString formatting functions 定义 说明
%@ Objective-C object, printed as the string returned by descriptionWithLocale: if available, or description otherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function.
%% ‘%’ character
%d, %D, %i Signed -bit integer (int)
%u, %U Unsigned -bit integer (unsigned int)
%hi Signed -bit integer (short)
%hu Unsigned -bit integer (unsigned short)
%qi Signed -bit integer (long long)
%qu Unsigned -bit integer (unsigned long long)
%x Unsigned -bit integer (unsigned int), printed in hexadecimal using the digits – and lowercase a–f
%X Unsigned -bit integer (unsigned int), printed in hexadecimal using the digits – and uppercase A–F
%qx Unsigned -bit integer (unsigned long long), printed in hexadecimal using the digits – and lowercase a–f
%qX Unsigned -bit integer (unsigned long long), printed in hexadecimal using the digits – and uppercase A–F
%o, %O Unsigned -bit integer (unsigned int), printed in octal
%f -bit floating-point number (double)
%e -bit floating-point number (double), printed in scientific notation using a lowercase e to introduce the exponent
%E -bit floating-point number (double), printed in scientific notation using an uppercase E to introduce the exponent
%g -bit floating-point number (double), printed in the style of %e if the exponent is less than – or greater than or equal to the precision, in the style of %f otherwise
%G -bit floating-point number (double), printed in the style of %E if the exponent is less than – or greater than or equal to the precision, in the style of %f otherwise
%c -bit unsigned character (unsigned char), printed by NSLog() as an ASCII character, or, if not an ASCII character, in the octal format \\ddd or the Unicode hexadecimal format \\udddd, where d is a digit
%C -bit Unicode character (unichar), printed by NSLog() as an ASCII character, or, if not an ASCII character, in the octal format \\ddd or the Unicode hexadecimal format \\udddd, where d is a digit
%s Null-terminated array of -bit unsigned characters. %s interprets its input in the system encoding rather than, for example, UTF-.
%S Null-terminated array of -bit Unicode characters
%p Void pointer (void *), printed in hexadecimal with the digits – and lowercase a–f, with a leading 0x
%L Length modifier specifying that a following a, A, e, E, f, F, g, or G conversion specifier applies to a long double argument
%a -bit floating-point number (double), printed in scientific notation with a leading 0x and one hexadecimal digit before the decimal point using a lowercase p to introduce the exponent
%A -bit floating-point number (double), printed in scientific notation with a leading 0X and one hexadecimal digit before the decimal point using a uppercase P to introduce the exponent
%F -bit floating-point number (double), printed in decimal notation
%z Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument
%t Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a ptrdiff_t or the corresponding unsigned integer type argument
%j Length modifier specifying that a following d, i, o, u, x, or X conversion specifier applies to a intmax_t or uintmax_t argument 平台依赖
Mac OS X uses several data types—NSInteger, NSUInteger,CGFloat, and CFIndex—to provide a consistent means of representing values in - and -bit environments. In a -bit environment, NSInteger and NSUInteger are defined as int and unsigned int, respectively. In -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 . Note that in some cases you may have to cast the value.
Table Format specifiers for data types 类型 定义 建议
NSInteger %ld or %lx Cast the value to long
NSUInteger %lu or %lx Cast the value to unsigned long
CGFloat %f or %g %f works for floats and doubles when formatting; but see below warning when scanning
CFIndex %ld or %lx The same as NSInteger
pointer %p %p adds 0x to the beginning of the output. If you don’t want that, use %lx and cast to long.
long long %lld or %llx long long is -bit on both - and -bit platforms
unsigned long long %llu or %llx unsigned long long is -bit on both - and -bit platforms The following example illustrates the use of %ld to format an NSInteger and the use of a cast. NSInteger i = ;
printf("%ld\n", (long)i); In addition to the considerations mentioned in Table , 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. CGFloat imageWidth;
double tmp;
sscanf (str, "%lf", &tmp);
imageWidth = tmp; It is important to remember that %lf does not represent CGFloat correctly on either - or -bit platforms. This is unlike %ld, which works for long in all cases.

Objective-C中的占位符,打印BOOL类型数据的更多相关文章

  1. Java C# C语言中的占位符

    一般拼接一段字符串在编程中是很常见的事,下面简单做个总结: 什么是占位符?占位符就是先占住一个固定的位置,等着你再往里面添加内容的符号. 1.Java中处理方法: package com.amos; ...

  2. 安卓编程资源文件string中对占位符的使用详解

    这里将为你详细介绍占位符的使用,将其学以致用,可以达到简化布局文件,减少字符串资源量. 1.在资源文件中的使用. 打开资源文件中的strings.xml文件,进行编辑.如下图所示: 图  1.0 2. ...

  3. 【占位符替换】替换String中的占位符标志位{placeholder}

    概述 占位符替换, 占位符表示为:{placeholder}; 示例:替换如下{xxx}占位符中的内容 "名字:{name},年龄:{age},学校:{school}" 提供了两种 ...

  4. Java替换字符串中的占位符

    在开发中,会有动态配置字符串其中的某些字符,如何使用字符中的占位符,并且在代码动态替换占位符实现动态配置字符串! 1.定义字符串时,再string文件添加字符串: 注意!记得要在字符文件中加上这些: ...

  5. 使用MessageFormat替换字符中的占位符

    使用String.format可以实现字符串的格式化功能,即将后面参数中的值替换掉format中的%s,%d这些值.但MessageFormat更为强大,不用管传入值是字符串还是数字,使用占位符即可. ...

  6. hibernate查询语句hql中的占位符?参数与命名参数:name设值方式搞混

    先贴出异常 Struts has detected an unhandled exception: Messages: Position beyond number of declared ordin ...

  7. C# 中的占位符本质

    占位符本质 1.占位符是相对于String字符串类型而言的. 2.占位符其实就是调用String.Format()方法.把指定的变量拼接到定义好的字符串模板中组成新的字符串.

  8. spring 的 PropertyPlaceholderConfigurer读取的属性怎么访问 (java访问方式,不是xml中的占位符哦)及此类的应用

    一.1.占位符的应用:(@Autowired注解方式,不需要建立set与get方法了,xml注入也不需要写了) http://www.cnblogs.com/susuyu/archive/2012/0 ...

  9. C#中的占位符

    当我们需要在屏幕上输出一句话的时候,如果不断的使用+来连接各个字符串,一是容易出错,二是代码显示的非常乱.这时候,占位符就能够发挥作用! 占位符: string name="张三" ...

随机推荐

  1. Android-锁屏功能

    当屏幕多久没有点击的时候,进行某种操作就是所谓的锁屏功能. onCreate: public void addRunnable() { handler.postDelayed(runnable, Co ...

  2. cat主要有三大功能

    cat主要有三大功能:1.一次显示整个文件.$ cat filename2.从键盘创建一个文件.$ cat > filename     只能创建新文件,不能编辑已有文件.3.将几个文件合并为一 ...

  3. C#日期格式精确到毫秒以及上下午

    有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2009-6-24 14:33:34 如果要换成成200906,06-2009,2009-6-24或更多的该怎么办呢 我们要用到:DateT ...

  4. 【HDOJ】4516 威威猫系列故事——因式分解

    可解的算法太多了,采用的算法是试x的值.注意题目的输入x^3-2x^2不会写成x^3+-2x^2.一直RE在这儿. /* 4516 */ #include <iostream> #incl ...

  5. Nginx+Keepalived 做负载均衡器

    1.安装 keepalived   1 2 3 4 5 6 7 8 9 tar zxvf keepalived-XXXX.tar.gz ./configure --prefix=/usr/local/ ...

  6. hadoop2.2编程:Tool, ToolRunner, GenericOptionsParser, Configuration

    继承关系:   1. java.util Interface Map.Entry<K,V> description: public static interface Map.Entry&l ...

  7. 基于.NET平台的分布式应用程序的研究

    摘 要:.NET框架是Microsoft用于生成分布式Web应用程序和Web服务的下一代平台.概述了用于生成分布式应用程序的.NET框架的基本原理.重点讲述了.NET框架的基础:公共语言运行时(CLR ...

  8. rfc all download

    http://www.rfc-editor.org/download.html about RTSP http://en.wikipedia.org/wiki/Real_Time_Streaming_ ...

  9. nginx根据域名做http,https分发

    omcat端口:8080 做好虚拟主机 参照我的另一篇文章nginx端口:80 根据域名分派 在conf/nginx.conf中的http中增加 include www.huozhe.com.conf ...

  10. EventHandlerList z

    写一个类时,有时候会在同一个类上添加很多事件,事件很多的话,是不容易管理的,.NET提供的EventHandlerList可以辅助多个事件的管 理,但不方便的地方是,它不是类型安全的,缺少类型安全,多 ...