最佳答案
我正在尝试快速地进行 IFSCCode 验证,但是我面临的问题是我无法获取字符串中的前四个字母。
综合家庭服务中心代码示例:
ABCD0200000
IFSC 守则如下:
我已经在 Objective C 中编写了 ifs 代码验证的代码,但是我对 Swift 并不熟悉,所以在 Swift 中复制同样的代码时遇到了问题。
以下是我在目标 C 中编写的代码:
- (BOOL)validateIFSCCode:(NSString*)ifsccode {
if (ifsccode.length < 4) {
return FALSE;
}
for (int i = 0; i < 4; i++) {
if (![[NSCharacterSet letterCharacterSet]
characterIsMember:[ifsccode characterAtIndex:i]]) {
return FALSE;
}
}
if (ifsccode.length < 10) {
return FALSE;
}
if ([ifsccode characterAtIndex:4] != '0') {
return FALSE;
} else {
return TRUE;
}
}
在 Swift 3里
func validateIfscCode(_ ifscCode : String) -> Bool{
if(ifscCode.characters.count < 4){
return false;
}
for( _ in 0 ..< 4){
let charEntered = (ifscCode as NSString).character(at: i)
}
if(ifscCode.characters.count < 10){
return false;
}
let idx = ifscCode[ifscCode.index(ifscCode.startIndex, offsetBy: 4)]
print("idx:%d",idx)
if (idx == "0"){
}
return true
}