简体   繁体   English

包含“&”的 NSString 如何在目标 c 中转换为“\&”

[英]How NSString containing "&" convert to " \u0026" in objective c

例如:“运输和物流”到“运输\&物流”

The thing you are trying to do is to convert Text to Unicode Hex Representation.您要做的是将文本转换为 Unicode 十六进制表示。

the code below:下面的代码:

    NSString *amp = @"&";
    char ch = [amp characterAtIndex:0];
    NSLog(@"amp is %04x", ch);

printing out in console: amp is 0026在控制台打印出来: amp 是 0026

(4 in %04x is number of characters to log) now the deal is to represent 0026 as \&, you can use stringWithFormat method of NSString, to achieve the result, if you want it as string. (%04x 中的 4 是要记录的字符数)现在的交易是将 0026 表示为 \&,您可以使用 NSString 的 stringWithFormat 方法来实现结果,如果您想要它作为字符串。

And it is not clear, if you need to convert only ampersand - you should search for it in string.并且不清楚,如果您只需要转换 & 符号 - 您应该在字符串中搜索它。

& 在 unicode 字符中是 \& 并且引导程序将接受 %26 作为 &

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM