You have a string of characters and you want to find the index of the first occurrence of a character.
For example, in the string "This is a string," the index of the character "a" is 8.
P:You could solve this problem using the following code snippet:
var c :Character var found = false var index = 0/*from w w w.ja v a 2s. c om*/ for c in "This is a string" { if c != "a" && !found { index = index + 1 } else { found = true } } print("Position of 'a' is \(index)")