How to get first four letters from string in Swift 3?
<p>I am trying to do IFSCCode validation in swift, but the problem I'm facing is I am not able to fetch the first four letters in string.</p>

<p>IFSC Code example:</p>

<blockquote>
  <p>ABCD0200000</p>
</blockquote>

<p>This is how an IFSC Code looks:</p>

<ol>
<li>First four characters in IFSC Code are always alphabets</li>
<li>Fifth character is always a zero.</li>
<li>And rest can be anything</li>
<li>The length of IFSC Code should not be greater than or less than 11. It should 11 in length.</li>
</ol>

<p>I have written code for ifs code validation in Objective C, but I am not that familiar in Swift so getting a problem in replicating the same in Swift.</p>

<p>The following is the code which I have written in Objective C:</p>

<pre><code>- (BOOL)validateIFSCCode:(NSString*)ifsccode {
  if (ifsccode.length &lt; 4) {
    return FALSE;
  }
  for (int i = 0; i &lt; 4; i++) {
    if (![[NSCharacterSet letterCharacterSet]
            characterIsMember:[ifsccode characterAtIndex:i]]) {
      return FALSE;
    }
  }
  if (ifsccode.length &lt; 10) {
    return FALSE;
  }
  if ([ifsccode characterAtIndex:4] != '0') {
    return FALSE;
  } else {
    return TRUE;
  }
}
</code></pre>

<p>In Swift 3</p>

<pre><code>func validateIfscCode(_ ifscCode : String) -&gt; Bool{
    if(ifscCode.characters.count &lt; 4){
        return false;
    }

    for( _ in 0 ..&lt; 4){
        let charEntered = (ifscCode as NSString).character(at: i)
    }
    if(ifscCode.characters.count &lt; 10){
        return false;
    }

    let idx = ifscCode[ifscCode.index(ifscCode.startIndex, offsetBy: 4)]

    print("idx:%d",idx)
    if (idx == "0"){
    }
    return true
}
</code></pre>