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)];
}
4

1 回答 1

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)];
}
于 2012-10-15T01:02:56.693 回答