zoukankan      html  css  js  c++  java
  • 过滤字符串中的非汉字、字母、数字

    1、过滤字符串中的非汉字、字母、数字

    /************ 控制器的view 加载完毕 的时候调用 *****************************/
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        NSString *originalString = @"非汉字 !@##@¥、字母 adafsa、#@#@#¥数字 空 格121223123¥¥#";
        NSString *resultString = [self filterCharactor:originalString withRegex:@"[^a-zA-Z0-9u4e00-u9fa5\s+]"];
        
        NSLog(@"%@", resultString);
    }
    #pragma mark - ************************************ 逻辑调用备用 *************************************************
    /************ 过滤字符串中的非汉字、字母、数字 *****************************/
    - (NSString *)filterCharactor:(NSString *)string withRegex:(NSString *)regexStr {
        
        NSString *filterText = string;
        NSError *error = NULL;
        NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:NSRegularExpressionCaseInsensitive error:&error];
        NSString *result = [regex stringByReplacingMatchesInString:filterText
                                                           options:NSMatchingReportCompletion
                                                             range:NSMakeRange(0, filterText.length)
                                                      withTemplate:@""];
        return result;
    }
    

    2、结果

  • 相关阅读:
    【案例】ora600
    Oracle 10046 event
    Oracle redo与undo浅析
    BUFFER CACHE和SHARED POOL原理
    oracle体系结构基础
    Oracle-buffer cache、shared pool
    获取oracle数据库对象定义
    ORA-20011
    expdp/impdp中NETWORK_LINK参数使用
    day03-Python基础
  • 原文地址:https://www.cnblogs.com/CH520/p/9771532.html
Copyright © 2011-2022 走看看