swift - Get starting position of a substring not counting emoji as one character ios -
i'm trying find starting positions of substring within string. it's returning correct index if it's characters without emoji. however, when special characters emojis used, returned index not correct. want count each emoji or character 1 character. here 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!
Comments
Post a Comment