i'm trying to find the starting positions of a substring within a string. It's only returning the correct index if it's just characters without any emoji. However, when special characters like emojis are used, the returned index is not correct. I want to count each emoji or character as one character. Here is my code:
extension String {
func index(of string: String, options: CompareOptions = .literal) -> Index? {
return range(of: string, options: options)?.lowerBound
}
func indexes(of string: String, options: CompareOptions = .literal) -> [Index] {
var result: [Index] = []
var start = startIndex
while let range = range(of: string, options: options, range: start..<endIndex) {
result.append(range.lowerBound)
start = range.upperBound
}
return result
}
}
Any suggestions? Thanks!