how to find the index of a character in a string from specific position

I know how to find an index of a character like the following:

func indexOfCharacter(myString:String, char: Character) -> Int {
        if let idx = find(myString, char) {
            return distance(self.startIndex, idx)
        }else{
            return -1;
        }

    }

How can I look for an index after a specific position ?

example:
myString=”abcdabcd”

I would like to get the index of the second ‘d’ = 7

indexOfCharacter(myString,character : 'd',fromIndex: 4);

any help ?


Source: ios

Leave a Reply