zoukankan      html  css  js  c++  java
  • NSString里面的数字

    0-9ASCII码:48 - 57

    方法一:

    //遍历NSString里面的数字

        NSString *str = @"ssdg0db9f567dazy";

        NSMutableString *strM = [NSMutableString string];

        for (int i = 0; i < str.length; i++) {

            unichar a =[str characterAtIndex:i];        

            if (!(a > 47 && a < 58) ) {

                //拼接字符串:方法一

                NSString *strResult = [str substringWithRange:NSMakeRange(i, 1)];

                [strM appendString:strResult];

                //拼接字符串:方法二

                //[strM appendFormat:@"%c",a];

            }

        }

      NSLog(@“%@",strM);

    方法二:利用正则表达式来实现

    #import "GJViewController.h"

    #import "NSString+Regex.h"

    @interface GJViewController ()

    @end

    @implementation GJViewController

    - (void)viewDidLoad

    {

        [super viewDidLoad];

    NSString *str = @"zhang23g114jn889"; 

        NSRegularExpression *regex = [NSRegularExpression

                                      regularExpressionWithPattern:@"\D*"

                                      options:NSRegularExpressionCaseInsensitive | NSRegularExpressionDotMatchesLineSeparators

                                      error:nil];

        NSArray *result = [regex matchesInString:str options:0 range:NSMakeRange(0, str.length)];

        NSMutableString *strM = [NSMutableString string];

        for (NSTextCheckingResult *resultCheck in result) {

            if (resultCheck.range.length > 0) {

                [strM appendString:[str substringWithRange:resultCheck.range]];

            }

        }

        NSLog(@"%@",strM);

    }

  • 相关阅读:
    python Unittest中setUp与setUpClass的区别
    Python的range和xrange的区别
    Python列表中的列表元素(嵌套列表)访问
    python字符串转为列表
    python正则匹配
    Python自动化测试用例设计--自动化测试用例与手工测试用例区别与联系
    Python+Selenium学习--自动化测试模型
    Python+Selenium学习--cookie处理
    Python+Selenium学习--控制浏览器控制条
    Python+Selenium学习--下载文件
  • 原文地址:https://www.cnblogs.com/bluceZ/p/4629439.html
Copyright © 2011-2022 走看看