NSString 格式符

关于在线excel插件Univer笔记教程 univer在线excel插件确实是够强大,但也存在不少bug,用户用起来是真的很爽,和本地的wps差不多,但真正的开发起来是真的费劲。由于文档提供的信息不足,我们很多功能只能去看他们插件里的源代码,然后一点点测试,一点点尝试研究。此文章可省去五天的研究成本 阅读详情

String Format Specifiers

This article summarizes the format specifiers supported by string formatting methods and functions.

Format Specifiers

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.

Table 1  Format specifiers supported by the  NSString formatting methods and CFString formatting functions

Specifier

                        

Description

%@

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

Signed 32-bit integer (int).

%u, %U

Unsigned 32-bit integer (unsigned int).

%x

Unsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and lowercase a–f.

%X

Unsigned 32-bit integer (unsigned int), printed in hexadecimal using the digits 0–9 and uppercase A–F.

%o, %O

Unsigned 32-bit integer (unsigned int), printed in octal.

%f

64-bit floating-point number (double).

%e

64-bit floating-point number (double), printed in scientific notation using a lowercase e to introduce the exponent.

%E

64-bit floating-point number (double), printed in scientific notation using an uppercase E to introduce the exponent.

%g

64-bit floating-point number (double), printed in the style of %e if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise.

%G

64-bit floating-point number (double), printed in the style of %E if the exponent is less than –4 or greater than or equal to the precision, in the style of %f otherwise.

%c

8-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

16-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 8-bit unsigned characters. Because the %s specifier causes the characters to be interpreted in the system default encoding, the results can be variable, especially with right-to-left languages. For example, with RTL, %s inserts direction markers when the characters are not strongly directional. For this reason, it’s best to avoid %s and specify encodings explicitly.

%S

Null-terminated array of 16-bit Unicode characters.

%p

Void pointer (void *), printed in hexadecimal with the digits 0–9 and lowercase a–f, with a leading 0x.

%a

64-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

64-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

64-bit floating-point number (double), printed in decimal notation.

Table 2  Length modifiers supported by the  NSString formatting methods and CFString formatting functions

Length modifier

Description

h

Length modifier specifying that a following d, o, u, x, or X conversion specifier applies to a short or unsigned shortargument.

hh

Length modifier specifying that a following d, o, u, x, or X conversion specifier applies to a signed char or unsigned charargument.

l

Length modifier specifying that a following d, o, u, x, or X conversion specifier applies to a long or unsigned long argument.

ll, q

Length modifiers specifying that a following d, o, u, x, or X conversion specifier applies to a long long or unsigned long long argument.

L

Length modifier specifying that a following a, A, e, E, f, F, g, or G conversion specifier applies to a long double argument.

z

Length modifier specifying that a following d, 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, 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, o, u, x, or X conversion specifier applies to a intmax_t or uintmax_t argument.

Platform Dependencies

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 3. Note that in some cases you may have to cast the value.

Table 3  Format specifiers for data types

Type

Format specifier

Considerations

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 note the technique described below for scanning.

CFIndex

%ld or %lx

The same as NSInteger.

pointer

%p or %zx

%p adds 0x to the beginning of the output. If you don't want that, use %zx and no typecast.

The following example illustrates the use of %ld to format an NSInteger and the use of a cast.

NSInteger i = 42;
printf("%ld\n", (long)i);

In addition to the considerations mentioned in Table 3, 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 32- or 64-bit platforms. This is unlike %ld, which works for long in all cases.

RK3576 调试ov2735 mipi-csi摄像头 摘要:本文记录了基于RK3576平台调试OV2735 MIPI摄像头的全过程。开发环境采用Linux 6.1内核和Buildroot文件系统。调试步骤包括:1)硬件检查(电源、晶振和引脚连接);2)驱动配置(设备树节点、ISP通道设置);3)驱动验证(通过ID检测和I2C工具测试);4)推流测试(使用v4l2和gstreamer工具)。重点解决了复位引脚配置、时钟命名匹配等关键问题,并通过寄存器检查确保初始化正常。最终实现了摄像头数据流的成功输出,为嵌入式视觉应用开发提供了完整参考方案。 阅读详情

相关推荐

R语言安装包镜像报错?5分钟教你快速切换国内镜像源(含清华/阿里云配置)

本文详细介绍了R语言安装包镜像报错的解决方案,包括如何快速切换国内镜像源(如清华、阿里云等),解决'无法读写貯藏處索引'等常见问题。通过图形界面和命令行两种方式,帮助用户高效配置镜像源,提升R语言包安装速度与稳定性。

weixin_29053073的博客 418

Bool类型值的输出

nslog输出bool类型的变量可以使用%i或%s 对于其他一些变量或对象的输出可以参考如下: Specifier Description %@ Objective-C object, printed as the string returned by descriptionWithLocale: if av

silva_831的专栏 6885

AAAI2024最佳解读|FontDiffuser One-Shot Font Generation via Denoising Diffusion with Multi-Scal

本文提出了一种名为FontDiffuser的基于扩散的单次字体生成方法,旨在通过去噪扩散模型生成模仿参考图像风格的字体,同时保留源图像的内容。尽管现有的字体生成方法在性能上取得了一定的进展,但在处理复杂字符和大风格变化时仍面临挑战。FontDiffuser通过引入多尺度内容聚合(MCA)模块,有效结合不同尺度的全局和局部内容线索,从而增强复杂字符的笔画保留能力。此外,文章还提出了一种风格对比细化(SCR)模块,用于风格表示学习,利用风格提取器从图像中分离风格,并通过精心设计的风格对比损失来监督扩散模型。

haimianxiaobao11的博客 1190

android bool 命名空间,综合:bool类型 命名空间 输入输出

/*******************************************************//* 知识点:bool类型命名空间输入输出 *//* 题目要求: *//* 使用一个函数找出一个整型数组中的最大值或最小值 *//***...

weixin_35408656的博客 178

SIwave仿真手册——软件基础(一)

最近在学习SIWAVE,在这里将自己的笔记整理一下,做一个专题。希望对大家有帮助,这个会持续更新的。仅限于软件操作学习,不涉及信号完整性的讨论。

luohuo9844的博客 4万+

超详细的YOLOv8项目组成解析:一站式指南了解其架构与组件

最近的更新是关于“Segment ONNX Runtime example”的,意味着它添加了对ONNX运行时的支持,特别是针对模型分割功能的支持。这些文件和文件夹共同工作,以确保 YOLOv8 的文档是全面的、多语言的,并且始终保持最新。这些示例涵盖了从基本的对象检测到更复杂的图像分割和视频处理任务,为开发者提供了丰富的学习资源和应用指导。最近的更新也是关于 ONNX 运行时示例。这些文件夹共同构成了 YOLOv8 的基础框架,从数据处理和模型配置到实际的训练和推理引擎,以及实用工具和高级功能的实现。

CDBmax的博客 1万+

NSLog打印自定义对象

我们在开发中,如果直接使用NSLog打印对象,则会打印对象的指针(如下图) 但我们常常希望打印的是对象的属性的值,因此我们需要重写自定义类的description方法(打印日志时,对象会收到description消息,在description方法返回打印的字符串),如下: -(NSString*)description{ return [NSString stringW

dolacmeng的专栏 4980

基于51单片机的智能花盆灌溉系统设计与实现

本文详细介绍了基于51单片机的智能花盆灌溉系统设计与实现,通过DS18B20温度传感器、土壤湿度传感器和LCD1602显示屏等硬件模块,结合精确的算法控制,实现自动监测与灌溉。系统解决了传统灌溉依赖定时器、缺乏可视化界面的问题,适合上班族、园艺爱好者和植物园工作人员使用,有效提升植物养护效率。

honey的博客 1014

NSLog各种打印

NSLog各种打印    分享类型:应用开发相关 %@ 对象 %d,%i 整型 (%i的老写法) %hd 短整型 %ld , %lld 长整型 %u 无符整型 %f 浮点型和double型 %0.2f 精度浮点数,只保留两位小数 %x:    为32位的无符号整型数(unsigned int),打印使用数

476

在Keil uv5里面添加STC元器件库,不影响其他元件

先到网上下载stc.CBD(宏晶网站的地址实效了)还有STC新系列单片机的头文件,宏晶的网站就有1、在Keil/C51/INC下新建目录"STC"文件夹, 把所有STC新系列单片机的头文件拷贝到"STC"目录下。2、下载的用于keil下的STC器件数据库更名为STC.CDB并拷贝到Keil/UV4目录下。3、打开Keil文件夹下的TOOLS.ini文件。4、在[UV2]下键入CDB0="UV2\S

技术联盟 1万+

FANUC机器人通过ROBOGUIDE实现与实际的机器人进行程序导入导出的具体方法示例

FANUC机器人通过ROBOGUIDE实现与实际的机器人进行程序导入导出的具体方法示例

Robot_PLC_HMI_Automation 6534

printf输出bool值 | printf转换符

printf输出bool值 | printf转换符

qq_34761779的博客 1万+

深度解析电力负荷预测:基于深度学习的完整实战指南

电力负荷预测是智能电网运行中的核心技术之一,准确的负荷预测对于电网的稳定运行、电力市场交易以及能源调度具有重要意义。本文将详细介绍电力负荷预测的完整解决方案,从数据预处理、特征工程到模型构建与评估,提供完整的可执行代码。我们将使用LSTM(长短期记忆网络)和Transformer两种主流深度学习模型进行实现,并通过实际数据集验证模型效果。电力负荷预测是指根据历史负荷数据、气象因素、时间特征等多维信息,预测未来某一时段的电力需求。超短期负荷预测:未来几分钟到几小时短期负荷预测:未来1天到1周中期负荷预测。

YOLO 111

CGFloat转NSString保持原有的精度,末尾不添加0

CGFloat转NSString保持原有的精度,避免末尾补0的情况

qq_43441647的博客 545

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Objective-C使用静态方法创建字符串对象

我们不仅可以直接通过给字符串直接赋值的方式来创建一个NSString对象,还可以使用NSString的静态方法(类方法)来创建对象。实现如下: (1) NSString *str = [NSString stringWithFormat:@"nihao:%d",100]; NSLog(@"%@",str); (2)我们点开进入stringWithFormat()方法,可以看到在NSStr

乞力马扎罗的雪CYF的博客 2036

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

使用NSString 的格式化大全

格式定义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 ...

dcj3sjt126com的专栏 310

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

IOS 学习日志 2015-3-13

前面几天在看C ,但是没有做笔记,现在在看Objective--C ,开始做笔记,希望每一天都有成长吧 Objective--C 关键字 1 @import 导入 注意<>||"" 其中""是自己写的文件 <> 是项目自带的 它类似于C语言中 #include ,但是它能防止重复导入 2 核心框架 Foundation 核心方法文件 Fou...

weixin_34419321的博客 88

UILabel赋值

两种赋值方式结果一样 1.self.resultLabel.text = [NSString stringWithFormat:@“%zd”,result];   %zd自动判断%d与%ld 2.self.resultLabel.text = @(result).description;

weixin_37664648的博客 967

去掉浮点多余的0

当arg为5.000时,用%f输出5.000,想输出5用%g,如下: [NSString stringWithFormat:@"%@:%g, %@:%g", L(@"STR_ID_TOPIC"), dto.topicCount, L(@"STR_ID_REPLY_NUM"), dto.replyCount] 转载于:https://www.cnblogs.com/ftrako/p/4079009...

weixin_34221332的博客 385

四十六、基础框架(四)字符串物件

在之前的程序当中,你  也  遇到过  字符串物件的。无论  什么时候,你  将  字符串  放  在一对双引号当中,你  就  创建了  一个字符串物件,就像  这样: 1@"编程很有趣。"在基础框架当中,有  一类物件  叫做  NSString。NSString这类物件  就是  字符串物件。在c语言当中  字符串  由  char类型的字符  构成,相应的  NSString类型

Alex1226的专栏 501

Objective-C打印BOOL型变量

有时候我们可能会定义一个  BOOL  b; b=YES; NSLog(@"BOOL--b-->%@",b); 然后运行程序就会崩溃,这是因为%@打印的是一个对象,BOOL是一个数据类型。 使用%@要求对应的参数必须是一个对象,并且还实现对象的description方法, 这样就可以打印出对象的内容了。 NSLog其实也就是调用该对象的descripti

zz_mm的专栏 845

OC关于NSString和NSMutableString方法的使用

//对象的声明 NSString对象是不可更改的 //返回的是字符串对象的地址,但不可以赋给可变字符串的指针 NSString *str=@"123456789"; //用一个字符串创建另一个字符串 NSString *str2=[[NSString alloc] initWithString:str]; //将c字符串转化为oc字符串 NSString *str3=[[NSStr

yang361的博客 503

Snail—OC学习之字符串NSString

首先,看一下不可变字符串NSString的方法 //最直接的定义一个字符串 NSString * str1 = @"我是Snail"; //通过一个字符串来创建另一个字符串 NSString * str2 = [[NSString alloc] initWithString:str1]; //下面这个方法跟上面这个是一个意思

树上的大腰子 617

NSString的用法

字符串是程序设计最常用的数据类型之一了。在Mac/ iPhone编程中,苹果为我们提供了一个不同的字符串类型NSString。有别与普通的String为数据类型,NSString是一个对象类型。NSString与NSMutableString最大的区别就是NSString创建之后该字符串的内容与长度不能再动态的更改,除非重新给这个字符串赋值。而NSMutableString创建赋值以后可以再更改该

Leeyehong_self的专栏 918

oc中的字符串 NSString

该博客是自己的学习笔记,写的比较随意。。。 1.创建字符串的方法: 1 //1用NSString 直接创建 2 NSString *str=@"hello world."; 3 //2用一个已存在的字符串来创建另一个字符串 传的参是一个字符串的地址 4 NSString *str2=[[NSString alloc] initWi...

119

OC基本数据结构-NSString

NSString基本方法

556
下一篇: NSString 用法
forceofwind
博客等级 码龄12年 2粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值