简体   繁体   中英

How do I convert an NSString value to NSMutableData? currency character

How do I convert an NSString currency character value to NSMutableData?

NSString* str = @"€120";
[mutableData appendData:[str dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]];

Print mutableData and out ?120 change the character for the character ?

How can I add this character?

The problem is that is not an ASCII character, as it did not exist at the time the ASCII charset was defined, so you can't use NSASCIIStringEncoding to encode it. If you use a more modern string encoding that supports the character, it will work. NSUTF8StringEncoding is generally a good choice.

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