美文网首页
把字符串替换成星号

把字符串替换成星号

作者: 失忆的程序员 | 来源:发表于2018-07-31 17:26 被阅读0次

//

        NSString *idSStr = @"12345678901234567";

        NSString *phoneStr = [self replaceStringWithAsterisk:idSStr startLocation:0 lenght:idSStr.length - 4 - 0];

        XPFLog(@" phoneStr : %@", phoneStr);

=======================================================

//把字符串替换成星号

- (NSString*)replaceStringWithAsterisk:(NSString*)originalStr startLocation:(NSInteger)startLocation lenght:(NSInteger)lenght {

    NSString*newStr = originalStr;

    for(inti =0; i < lenght; i++) {

        NSRangerange =NSMakeRange(startLocation,1);

        newStr = [newStrstringByReplacingCharactersInRange:range withString:@"*"];

        startLocation ++;

    }

    returnnewStr;

}

相关文章

网友评论

      本文标题:把字符串替换成星号

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