Inout String does not convert to String in Swift 3 range

I have the following code that works fine in Swift 2:

let myModifiedString = myOriginalString.replacingOccurrences(of: "#(?:\\S+)\\s?",
            with: "",
            options: .regularExpression,
            range: Range(myOriginalString.characters.indices))

However, I am updating my code to Swift 3, and I get the error message "inout String" does not convert to input "String".

The error occurs in myOriginalString.characters.indices.

I saw that Swift 3 made some changes to how ranges are implemented, as well as some String functions. I just cannot find a short solution to solve the problem and convert this statement into the corresponding Swift 3 syntax. What is the correct Swift 3 syntax for the statement?

+4
source share
1 answer

Swift 3 indices Collection of Index, Range. , , - :

let myModifiedString = myOriginalString.replacingOccurrences(of: "#(?:\\S+)\\s?",
                                                             with: "",
                                                             options: .regularExpression,
                                                             range: myOriginalString.startIndex..<myOriginalString.endIndex)
+2

Source: https://habr.com/ru/post/1656074/


All Articles