网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 iphone正则表达式的简单使用
范文
    在 4.0 之后,系统就有了它自己的类(nsregularexpression,nsregularexpression)来使用正则表达式,,之前都是要添加第三方类库 regexkitlite 来使用
    这两个类的简单使用:
    nsstring *str = @3sdfh*odsi;
    //匹配第一个字符是数字
    nsregularexpression *regex1 = [nsregularexpression regularexpressionwithpattern:@bd.* options:0 error:nil];
    if (regex1 != nil) {
    nstextcheckingresult *result1 = [regex1 firstmatchinstring:str options:0 range:nsmakerange(0, [str length])];
    if (result1) {
    nslog(@第一个是数字);
    }else{
    nslog(@第一个不是数字);
    }
    }
    //匹配特殊字符 w (w是大写)匹配任意不是字母,数字,下划线,汉字的字符
    nsregularexpression *regex2 = [nsregularexpression regularexpressionwithpattern:@.*w.* options:0 error:nil];
    if (regex2) {
    nstextcheckingresult *result2 = [regex2 firstmatchinstring:str options:0 range:nsmakerange(0, [str length])];
    if (result2) {
    nslog(@有特殊字符);
    }else{
    nslog(@没有特殊字符);
    }
    }
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/23 21:57:11