NSCharacterSet截取字符串


//需要被截取的字符串

NSString *textStr = textView.text;

//  不需要的字符串

        NSCharacterSet *cs = [NSCharacterSet characterSetWithCharactersInString:@“123456789-"];

//  结果       

        NSString *NoUserStr = [[textStr componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@"];


// end

 // ———————  以下是 再做一次反选———— 

         

        cs = [NSCharacterSet characterSetWithCharactersInString:NoUserStr];

        NSString *result = [[textStr componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];

        textView.text = result;


//=========================================

多用于登陆时,除去特殊符号

- (NSString *)stringByTrimmingCharactersInSet:(NSCharacterSet *)set;



你可能感兴趣的:(提取需要的字符串)