- 去除數(shù)字以外的所有字符
NSCharacterSet *setToRemove = [[ NSCharacterSet characterSetWithCharactersInString:@"0123456789"]invertedSet];
NSString *strPhone = user.phones[0];
strPhone = [[strPhone componentsSeparatedByCharactersInSet:setToRemove] componentsJoinedByString:@""];
- 去掉空格和換行符號的實(shí)質(zhì)就是替換掉對應(yīng)的字符
NSString* str=~~~~~~;
//1. 去除掉首尾的空白字符和換行字符
str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//2. 去除掉其它位置的空白字符和換行字符
str = [str stringByReplacingOccurrencesOfString:@"\r" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者