美文网首页
iOS通讯录手机号格式化

iOS通讯录手机号格式化

作者: 奋斗的蜗牛 | 来源:发表于2016-10-27 17:05 被阅读339次
    1. 去除数字以外的所有字符
    NSCharacterSet *setToRemove = [[ NSCharacterSet characterSetWithCharactersInString:@"0123456789"]invertedSet];
    NSString *strPhone = user.phones[0];
    strPhone  = [[strPhone componentsSeparatedByCharactersInSet:setToRemove] componentsJoinedByString:@""];
    
    1. 去掉空格和换行符号的实质就是替换掉对应的字符
    NSString* str=~~~~~~;
    //1. 去除掉首尾的空白字符和换行字符
    str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    //2. 去除掉其它位置的空白字符和换行字符
    str = [str stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    

    相关文章

      网友评论

          本文标题:iOS通讯录手机号格式化

          本文链接:https://www.haomeiwen.com/subject/jsksuttx.html