0
1 US Dollar = 3.673 United Arab Emirates Dirham

この文字列から値のみを取得するには3.673?

次のコードを試しましたが、うまくいきませんでした。

NSString *a = [[xmlParser array]objectAtIndex:2];
NSRange startRange = [a rangeOfString:@"="];
NSLog(@"%u",startRange.location+1);
NSRange endRange = [a rangeOfString:@" "];
NSLog(@"%u",endRange.location);
NSString *subString = [a substringWithRange:NSMakeRange(startRange.location + 1, endRange.location)];
NSLog(@"%@",subString);
4

4 に答える 4

4

これを使って:

 NSArray *aArray = [a componentsSeparatedByString:@" "]; //your string here
 NSString *dollarValue = [aArray objectAtIndex:4]; //get dollar value from array
 NSLog(@"%@",dollarValue);
于 2012-10-10T11:18:31.010 に答える
2

私は次のようなことをします...

NSArray *words = [string componentsSeparatedByString:@" "];

for (NSString *word in words) {
    //check for equals sign and then take the next one.
}
于 2012-10-10T11:18:41.810 に答える
1
str = [NSString stringWithFormat:@"1 US Dollar = 3.673 United Arab Emirates Dirham"];  
components = [str componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
str = [components objectAtIndex:4];
NSLog(@"Str:%@", str);
于 2012-10-10T11:26:31.923 に答える
0
 NSString *param = nil;
    NSRange start = [a rangeOfString:@"="];
    if (start.location != NSNotFound)
    {
        param = [a substringFromIndex:start.location + start.length];
        NSRange end = [param rangeOfString:@"United"];
        if (end.location != NSNotFound)
        {
            param = [param substringToIndex:end.location];
        }
    }
    NSLog(@"param: %@",param);
于 2012-10-10T11:22:33.787 に答える