Swift - Write program to find out the position of the "q" character in the string

Requirements

Given the following statement, write the solution to find out the position of the "q" character in the string:

var str1 = "The quick brown fox jumps over the lazy dog"

Hint

You can use the find() function together with the distance () function to obtain the position of the "q" character:

Demo

var str1 = "The quick brown fox jumps over the lazy dog"
let char:Character = "q"
if let charIndex = find(str1, char) {
   let charPosition = distance (str1.startIndex, charIndex)
   print(charPosition)  //4---
}

Related Exercise