2012-06-12 65 views

回答

0

我不會說這是從的NSString刪除不想要的字符的最佳方式,但我這樣做......這是偉大的。

NSString * str = @"your string"; 
NSMutableString * newString; 
int j = [str length]; 
for (int i=0; i<j; i++) {  
    if (([str characterAtIndex:i] >=65 && [str characterAtIndex:i] <=90) || ([str characterAtIndex:i] >=97 && [str characterAtIndex:i] <=122) ||[str characterAtIndex:i] == 32) { 
     [newString appendFormat:@"%c",[str characterAtIndex:i]]; 
    }    
} 

//([str characterAtIndex:i] >=65 && [str characterAtIndex:i] <=90) this is ASCII limit for A-Z 
//([str characterAtIndex:i] >=97 && [str characterAtIndex:i] <=122) this is ASCII limit for a-z 
//and [str characterAtIndex:i] == 32 is for space. 

現在,打印新的字符串

NSLog(@"%@",newString); 

讓我知道如果沃金爲您服務!

謝謝!

+0

解決了這個問題!謝謝你Vakul – 012346

+0

你的歡迎:-) – TheTiger

+0

改變了它,因爲這不是ISO10126d2Padding的工作原理,我很高興它爲這個特定的用例工作,但這不應該被普遍使用。 –