Find the nth unique character in a String.

String string = "krrishna"
def index = null;
int cnt = 0; 
int n = 4 // set this for any value for n

def findNthChar = {String str->
  for(int i =0 ;i<str.size();i++){
    if(str.count(str[i]) == 1){
      cnt++
      if(cnt == n){
        index = i
         return index
        }
      }
    }
  }

def res = findNthChar(string)
if(res){
   println "found character at index ${res} char is ${string[res]} "
}else{
   println "no character found"
}