gpt4 book ai didi

ios - Unicode在iOS中无法正常工作

转载 作者:行者123 更新时间:2023-12-01 18:10:43 25 4
gpt4 key购买 nike

将unit设置为\u20AC时,我的unicode为UILabel,但标签上却出现了unicode。有时它正在打印欧元,但大多数情况下是在标签上打印unicode。

我的代码在这里

    NSLog(@"Currecy %@",currencySymbol);
UILabel *priceLbl = [[UILabel alloc] initWithFrame:CGRectMake(180, 10, 45, 25)];

priceLbl.textColor = [UIColor whiteColor];
priceLbl.textAlignment = NSTextAlignmentCenter;
priceLbl.font = [UIFont fontWithName:@"ProximaNova-Bold" size:15];
priceLbl.tag = 1001;
fair = [NSString stringWithFormat:@"%d",arc4random()%50];
priceLbl.text = [NSString stringWithFormat:@"%@ %@",fair,currencySymbol];

输出
货币\ u20AC
Printing description of priceLbl:
<UILabel: 0x7faade3095a0; frame = (185 10; 50 25); text = '\u20AC'; userInteractionEnabled = NO; tag = 1001; layer = <_UILabelLayer: 0x7faadbd91bb0>>

enter image description here

我想尽一切可能设置输出。例如

enter image description here

获取服务器响应
{
currency = "\\u20AC";
description = "You have been successfully logged in.";
}

and the currency symbol replacing "\\" with "\"

NSString *currency = [response[@"currency"] stringByReplacingOccurrencesOfString:@"\\\\" withString:@"\\"];

最佳答案

NGUYEN MINH的答案为我工作如下:

NSString *currencySymbol = @"\\u20AC";
NSString *fair = @"1.99 ";

NSString *convertedString = currencySymbol;

CFStringRef transform = CFSTR("Any-Hex/Java");
CFStringTransform((__bridge CFMutableStringRef)convertedString, NULL, transform, YES);

label.text = [NSString stringWithFormat:@"%@ %@", fair, convertedString];

问题是您的currencySymbol包含: @"\\u20AC",它是6个字符的字符串,而不是一个字符串 @"\u20AC"
另一个可行的解决方案:
NSString *currencySymbol = @"\\u20AC";
NSString *fair = @"1.99 ";

currencySymbol = [NSString
stringWithCString:[currencySymbol cStringUsingEncoding:NSUTF8StringEncoding]
encoding:NSNonLossyASCIIStringEncoding];


label.text = [NSString stringWithFormat:@"%@ %@", fair, currencySymbol];

关于ios - Unicode在iOS中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32033313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com