美文网首页iOS开发iOS学习笔记
iOS-身份证中间数字设置为星号

iOS-身份证中间数字设置为星号

作者: FlyElephant | 来源:发表于2016-10-15 16:29 被阅读1474次

iOS中可以替换特定位置的字符,所以替换成星号非常简单,简单扩展一下字符串,方法如下:
<pre><code>`

  • (NSString *)replaceStringWithAsterisk:(NSInteger)startLocation length:(NSInteger)length {
    NSString replaceStr = self;
    for (NSInteger i = 0; i < length; i++) {
    NSRange range = NSMakeRange(startLocation, 1);
    replaceStr = [replaceStr stringByReplacingCharactersInRange:range withString:@"
    "];
    startLocation ++;
    }
    return replaceStr;
    }`</code></pre>

相关文章

网友评论

    本文标题:iOS-身份证中间数字设置为星号

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