Jon*_*nah 41 iphone objective-c nsstring
我有一个显示英寸的标签.我想用英寸符号(")或引号显示数字.我能用nsstring做这个吗?谢谢!
Jef*_*ley 109
当然,你只需要逃避引号.
NSString *someString = @"This is a quotation mark: \"";
NSLog(@"%@", someString );
Run Code Online (Sandbox Code Playgroud)
输出:
This is a quotation mark: "
Run Code Online (Sandbox Code Playgroud)
Bha*_*vin 17
您可以在此处使用Double Quote Escape Sequence.你需要使用反斜杠来逃避它:
NSString *str = @"Hello \"World\"";
NSLog(@"Output : %@",str);
Output : Hello "World"
Run Code Online (Sandbox Code Playgroud)
还有其他一些Escape序列.看看它:
\b Backspace
\f Form Feed
\n Newline
\t Horizontal Tab
\v Vertical Tab
\\ Backslash
\’ Single Quote
\” Double Quote
\? Question Mark
Run Code Online (Sandbox Code Playgroud)
使用反斜杠"已经提到了所以我回答的不同.你也可以使用ASCII代码.
ASCII码的"(双引号)为34.
NSString *str = [NSString stringWithFormat:@"%cThis is a quotation mark: %c", 34, 34];
NSLog(@"%@", str);
Run Code Online (Sandbox Code Playgroud)
输出是: "这是一个引号:"
Swift 4.0版本
let str = String(format: "%cThis is a quotation mark: %c", 34, 34)
print(str)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33367 次 |
| 最近记录: |