Convert String.index into int


I have a long String which I want to shorten step by step. The String contains a lot of characters which I don't need, but the String has some patterns, so I search for a character, shorten the original String or rather the copy of the original String and search for the next relevant character.

Code Block
let searchname = ""
        let f = globalString.firstIndex(of: "\"")
        self.globalString.dropFirst(f)
        let e = globalString.firstIndex(of: "\\")
        let substring = globalString[...e!]
        return String(substring)

In line three I get the error, that an Integer is needed and a String.index is given. How can I transform the String.index to an Integer or is there another possibility to this in code?
Answered by Claude31 in 663301022
If you use
Code Block
if f != nil {
globalString = String(globalString[f!...]) //.dropFirst(f)
}

Accepted Answer
If you use
Code Block
if f != nil {
globalString = String(globalString[f!...]) //.dropFirst(f)
}

Thank you 🙏
Convert String.index into int
 
 
Q