-(NSString *)returnBankCard:(NSString *)BankCardStr{
self.originString = BankCardStr;
BankCardStr = [self getValidStringWithString:BankCardStr];
if (BankCardStr.length > 5) {
NSString *formerStr = [BankCardStr substringToIndex:0];
NSString *str1 = [BankCardStr stringByReplacingOccurrencesOfString:formerStr withString:@""];
NSString *endStr = [BankCardStr substringFromIndex:BankCardStr.length-4];
endStr = [self getValidStringWithString:endStr];
NSString *str2 = [str1 stringByReplacingOccurrencesOfString:endStr withString:@""];
NSString *middleStr = [str2 stringByReplacingOccurrencesOfString:str2 withString:@"**** **** **** "];
NSString *CardNumberStr = [formerStr stringByAppendingFormat:@"%@%@",middleStr,endStr];
return CardNumberStr;
}else {
return BankCardStr;
}
}
-
(NSString *)getValidStringWithString:(NSString *)string {
NSString *returnString = string;if (![returnString isKindOfClass:[NSString class]]) {
returnString = @"";
}if (returnString.length <= 0) {
returnString = @"";
}NSString *noSpaceString = [returnString copy];
returnString = [noSpaceString stringByReplacingOccurrencesOfString:@" " withString:@""];
if (noSpaceString.length <= 0) {
returnString = @"";
}return returnString;
}
网友评论