stringByAppendingString提供不可预测的结果

时间:2013-06-26 00:20:26

标签: objective-c string concatenation string-concatenation

新手问题 - 但很需要答案......在这个循环中,字符串变量lineString有时会为null,有时会在其末尾附加额外的乱码。如果有人能够解释为什么会这样,我将不胜感激....在此先感谢:

NSMutableArray* lineStrings = [[NSMutableArray alloc] initWithArray:[fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]];
NSMutableArray *linestoJoin = [[NSMutableArray alloc] init];
int i = 0;
for (NSString *currentLine in lineStrings) {
        NSArray *arr = [currentLine componentsSeparatedByString:@","];
        NSString *TSN = (NSString *)[arr objectAtIndex:0];
        NSString *speciesName = (NSString *)[arr objectAtIndex:1];
   //This stringByAppendingString sometimes results in added garbage or nothing at all!!
        NSString *lineString = [[speciesName stringByAppendingString:@"," ] stringByAppendingString:TSN];
        [linestoJoin addObject:lineString];
        i++;
    }

0 个答案:

没有答案