Objective c 从带有符号的数组中添加项$

Objective c 从带有符号的数组中添加项$,objective-c,ios5,ios4,xcode4.2,ipad-2,Objective C,Ios5,Ios4,Xcode4.2,Ipad 2,我有一个数组,如果我在控制台中打印它,它会显示 Price Array=( "$100", "$300" ) 我需要在每个索引处添加对象,并在标签中显示它。请提出任何想法,在这种情况下,它将如何显示400美元符号? 我尝试了这个,因为我确实加载了 for (int j=0; j<[cartArray2 count]; j++) { itemPrize =[prizelabel.text floatValue]; tempVar=it

我有一个数组,如果我在控制台中打印它,它会显示

Price Array=(
    "$100",
    "$300"
)
我需要在每个索引处添加对象,并在标签中显示它。请提出任何想法,在这种情况下,它将如何显示400美元符号? 我尝试了这个,因为我确实加载了

for (int j=0; j<[cartArray2 count]; j++)
    {
        itemPrize =[prizelabel.text floatValue];
        tempVar=itemPrize;
        total=total+tempVar;
        NSString *strTotalAmt = [NSString stringWithFormat:@"%f",total];
        prizelabel.text=strTotalAmt;
    }
    NSLog( @"Toatl= %f",total);`
for (int j=0; j<[cartArray2 count]; j++)
{
    NSMutableString *cleanedText = [NSMutableString stringWithCapacity:0];

    NSString *newRecord = [[cartArray2 objectAtIndex:j] stringByReplacingOccurrencesOfString:@"$" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [[cartArray2 objectAtIndex:j] length])];
    [cleanedText appendFormat:@"%@\n", newRecord];

    NSLog(@"Cleaned=%@", cleanedText);
    itemPrize =[cleanedText intValue];
    tempVar=itemPrize;
    total=total+tempVar;
    NSString *strTotalAmt = [NSString stringWithFormat:@"%d",total];
    prizelabel.text=strTotalAmt;
}
NSLog( @"Toatl= %d",total);

for(int j=0;j要去掉$符号,你应该尝试:
[[itemPrize Components由字符串分隔:@“$”]objectAtIndex:1];
。然后你应该使用
stringWithFormat
方法来进行字符串格式化。

@Ajit Satarkar我们能看到一些代码吗?@我在视图中尝试过这个方法,确实加载了NSLog(@“Price Array=%@),Cartary2);对于(int j=0;j在调用floatValue之前,您需要去掉“$”。然后在打印结果时添加它。@实际上,$符号default ally的出现是因为我通过解析JSONI know得到了这些项,但您可以使用字符串操纵函数(想到子字符串)将其删除。