0

When I use this link to grab the item schema for TF2, (http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&language=en), under the attributes property, there's a list of every attribute in the game for TF2.

For example this is one such attribute:

{
            "name": "gesture speed increase",
            "defindex": 201,
            "attribute_class": "mult_gesture_time",
            "description_string": "+%s1% faster taunt speed on wearer",
            "description_format": "value_is_percentage",
            "effect_type": "positive",
            "hidden": false,
            "stored_as_integer": false
},

Under the "description_string" property you can see that the string uses a format specifier, but how do implement this in xcode. %s1 in xcode isn't the correct format specifier for strings, so how do I change it?

EDIT: What I'm trying to do it basically use [NSString stringWithFormat:@"+%s1% faster taunt speed on wearer", @"25"]. The problem is that when I NSLog this statement, the number doesn't show up and instead some weird symbols do. I want to have the statement "+25% faster taunt speed on wearer", so how do I achieve this?

4

1 回答 1

1

我认为您最好的方法是放弃stringWithFormat:,否则您将不得不转义%.

您可以执行以下任一操作:

%s1 的单次出现
如果你保证%s1只会出现一次,description_string你可以简单地使用:

NSString *description = @"+%s1% faster taunt speed on wearer";
description = [description stringByReplacingOccurrencesOfString:@"%s1" withString:@"25"];

%s1 多次出现

NSString *description = @"+%s1% faster taunt speed on wearer and +%s1 XP";
NSArray *values = @[@"25", @"1000"];
NSRange range = NSMakeRange(0, description.length);
NSUInteger index = 0;
while (range.location != NSNotFound) {
    range = [description rangeOfString:@"%s1" options:0 range:range];
    if (range.location != NSNotFound) {
        NSString *value = values[index];
        description = [description stringByReplacingCharactersInRange:range withString:value];
        range = NSMakeRange(range.location + value.length, description.length - (range.location + value.length));
    }
    index++;
}
于 2014-06-07T20:16:44.790 回答