2013-01-05 44 views
-2

我寫的會從一個字符串分隔內容的代碼,檢查內容有引號作爲第一個字符,然後將它們合併回兩個字符串: 一個開頭引號和一個沒有的引號。我有以下代碼,但是當我運行它時,它似乎沒有檢測到引號。檢查字符串第一個字符是引號

NSArray *detailTextLabelContentArray = [[NSArray alloc] initWithObjects:@"Some",@"Good",@"Stuff",@"\"Lazy\"", nil]; 
for (NSInteger index = 0; [detailTextLabelContentArray count] > index; index++) 
{ 
    if ([[detailTextLabelContentArray objectAtIndex:index] substringToIndex:1] != @"\"") 
    { 
     if (index == 0) 
     { 
      detailTextLabelContent = [[detailTextLabelContentArray objectAtIndex:index] substringToIndex:1]; 
     } 
     else 
     { 
      detailTextLabelContent = [NSString stringWithFormat:@"%@; %@",detailTextLabelContent,detailTextLabelContent = [[detailTextLabelContentArray objectAtIndex:index] substringToIndex:1]]; 
     } 
    } 
} 
NSLog(detailTextLabelContent); 

我在這裏做錯了什麼?

回答

4

不要使用!=或任何其他相等運算符來比較NSString秒。使用-[NSString isEqualToString:]代替:

![[[detailTextLabelContentArray objectAtIndex:index] substringToIndex:1] isEqualToString:@"\""] 

等式運算只比較指針平等,不反對平等。

相關問題