这是我的 NSLocalizedString:
"YOUR_INFO" = "%i is the first number, %i the second and %i the third";
稍后,我会像这样使用这个字符串:
NSString *detailString = [NSString stringWithFormat:NSLocalizedString(@"YOUR_INFO", nil), firstVal, secondVal, thirdVal];
我试图找出变量的索引,以便使用 NSMutableAttributedString
以粗体突出显示它们。
我本来打算使用 rangeOfString
,但后来我意识到,如果两个值相同,可能会有问题....
有没有办法以任何其他智能方式获取这些变量在字符串中的位置?
最佳答案
如果您只想将字符串中的每个数字加粗,您可以查看使用 enumerateSubstringsInRange:options:usingBlock:
枚举字符串中的每个单词并检查它是否为数字(longLongValue
)。当您找到数值时,枚举 block 会为您提供范围,以便您知道要在属性字符串中修改什么。
关于ios - 获取 NSLocalizedString 中参数的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22309703/