iOS 银行卡号密文形式展示

释放双眼,带上耳机,听听看~!
#import <Foundation/Foundation.h>
 
@interface BankModel : NSObject
@property(nonatomic,assign) NSInteger bankId;
@property(nonatomic,copy) NSString* bankImg;
@property(nonatomic,copy) NSString* bankName;
@property(nonatomic,copy) NSString*progressQueryUrl;
 
@property(nonatomic,assign) NSInteger*bankCardInformationId;
@property(nonatomic,copy) NSString*cardHolder;
@property(nonatomic,copy) NSString*bankCardNumber;
@property(nonatomic,copy) NSString*reservePhoneNumber;
@property(nonatomic,copy) NSString*bankCardType;
@property(nonatomic,copy) NSString* bankIcon;
 
- (NSString*)getNewStarBankNumWitOldNum;
 
@end
#import "BankModel.h"
@implementation BankModel
 
-(NSString *)getNewStarBankNumWitOldNum{
    NSString *bankNum = self.bankCardNumber;
    NSMutableString *mutableStr;
    if (bankNum.length) {
        mutableStr = [NSMutableString stringWithString:bankNum];
        for (int i = 0 ; i < mutableStr.length; i ++) {
            if (i>3&&i<mutableStr.length - 4) {
                [mutableStr replaceCharactersInRange:NSMakeRange(i, 1) withString:@"*"];
            }
        }
        NSString *text = mutableStr;
        NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789\b"];
        text = [text stringByReplacingOccurrencesOfString:@" " withString:@""];
        
        
        NSString *newString = @"";
        while (text.length > 0) {
            NSString *subString = [text substringToIndex:MIN(text.length, 4)];
            newString = [newString stringByAppendingString:subString];
            if (subString.length == 4) {
                newString = [newString stringByAppendingString:@" "];
            }
            text = [text substringFromIndex:MIN(text.length, 4)];
        }
        newString = [newString stringByTrimmingCharactersInSet:[characterSet invertedSet]];
        return newString;
    }
    return bankNum;
}
@end

 

人已赞赏
iOS文章

IOS11 UITableView刷新后 抖动(乱跳)

2019-12-10 17:27:18

iOS文章

iOS UICollectionViewCell自适应文字宽度

2019-12-10 18:39:50

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索