zoukankan      html  css  js  c++  java
  • 【小技巧】【源码】iOS复制电话本号码消除空格的方法

    iOS11,复制电话本联系人电话时,复制的不是11位的手机号而是15位,这是系统bug,iOS如何复制电话本号码消除空格呢,直接上代码

    //结束编辑
    -(void)textViewDidEndEditing:(UITextView *)textView
    {
    // 去掉数字
    NSLog(@"%lu",(unsigned long)textView.text.length);

    NSMutableString *strippedString = [NSMutableString
    stringWithCapacity:textView.text.length];
    NSScanner *scanner = [NSScanner scannerWithString:textView.text];
    NSCharacterSet *numbers = [NSCharacterSet
    characterSetWithCharactersInString:@"0123456789"];
    while ([scanner isAtEnd] == NO) {
    NSString *buffer;
    if ([scanner scanCharactersFromSet:numbers intoString:&buffer]) {
    [strippedString appendString:buffer];
    }
    else {
    [scanner setScanLocation:([scanner scanLocation] + 1)];
    }
    }
    NSLog(@"%@", strippedString);
    textView.text = strippedString;
    NSLog(@"%lu",(unsigned long)textView.text.length);
    }

  • 相关阅读:
    模线性方程理解
    dp水题
    静态字典树模板
    KMPnext数组循环节理解 HDU1358
    layer开发随笔
    javascript时间格式转换
    ubuntu16创建开机启动服务
    es集群搭建
    mongodb集群搭建
    zookeeper集群搭建
  • 原文地址:https://www.cnblogs.com/wangbinios/p/8474590.html
Copyright © 2011-2022 走看看