简体   繁体   中英

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

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

The thing you are trying to do is to convert Text to Unicode Hex Representation.

the code below:

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

printing out in console: amp is 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.

And it is not clear, if you need to convert only ampersand - you should search for it in string.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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