2012-10-15 75 views
0

我創建此方法時,只從字符串的末尾刪除空格,而不是開頭,而它完美地返回字符串,並執行我所需的操作,xcode接口告訴我「表達式結果未使用「在」for(lengthofthestring; lengthofthestring> 0; lengthofthestring--)「行,可以任何人告訴我爲什麼,在我撕下我所有的頭髮!謝謝。 但它運行良好,(我不想從商店任何麻煩)在字符串方法中未使用的表達式結果

繼承人的代碼...

-(NSString *)removeEndSpaceFrom:(NSString *)strtoremove{ 
    NSUInteger location = 0; 
    NSUInteger lengthofthestring = [strtoremove length]; 
    unichar charBuffer[lengthofthestring]; 
    [strtoremove getCharacters:charBuffer]; 
    ////////////// right here on the next line is where i'm getting the Expression result unused !!! 
    for (lengthofthestring ; lengthofthestring > 0; lengthofthestring--) { 
     if (![[NSCharacterSet whitespaceCharacterSet] characterIsMember:charBuffer[lengthofthestring - 1]]){ 
      break; 
     } 
    } 
    return [strtoremove substringWithRange:NSMakeRange(location, lengthofthestring - location)]; 
} 

回答

0

嗯,我定是這樣,但我仍然不知道回答上面的問題。

-(NSString *)removeEndSpaceFrom:(NSString *)strtoremove{ 
    NSUInteger location = 0; 
    unichar charBuffer[[strtoremove length]]; 
    [strtoremove getCharacters:charBuffer]; 
    int i = 0; 
    for (i = [strtoremove length]; i >0; i--){ 
     if (![[NSCharacterSet whitespaceCharacterSet] characterIsMember:charBuffer[i - 1]]){ 
      break; 
    } 
    } 
    return [strtoremove substringWithRange:NSMakeRange(location, i - location)]; 
} 
相關問題