我创建了这个方法,只删除字符串末尾的空格而不是开头,同时它完美地返回字符串并完成我需要的操作,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 :(得分: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)];
}