IOS学习之旅

过滤特殊字符串

2016-06-08  本文已影响84人  Less_Study
//定义一个特殊字符的集合
    NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"@/:;()¥「」"、;[]{}#%-*+=_\\|~<>$€^•'@#$%^&*()_+'\""];
    //过滤字符串的特殊字符
    NSString *oldString = _filterTextField.text;
    //stringByTrimmingCharactersInSet能做到的仅仅是把字符串两端的非法字符过滤,但是包含在字符串里非法字符则无能为力。
    NSString *newString = [[oldString componentsSeparatedByCharactersInSet:characterSet]componentsJoinedByString:@""];
    self.filterTextField.text = newString;
上一篇下一篇

猜你喜欢

热点阅读