I want to find the nsrange of the the word which is repeating in the string ,it search should be case sensitive .
for example :
the main string is let str = "Hi satheesh how are you doing ,Hellow satheesh1 did you find the answer for satheesh".
now I want to find the ranges of word "satheesh" ..expected nsrange count should be 2 .i.e [nsrange(location : 3, lenght : 8),[nsrange(other word satheesh)] it should not take the range of satheesh1 because satheesh != satheesh1 .
I am using below code
extension String {
func ranges(of substring: String, options: CompareOptions = [], locale: Locale? = nil) -> [Range<Index>] {
var ranges: [Range<Index>] = []
while let range = self.range(of: substring, options: options, range: (ranges.last?.upperBound ?? self.startIndex)..<self.endIndex, locale: locale) {
ranges.append(range)
}
return ranges
}
}
but the problem with this code is when finding the range it considering satheesh == satheesh1 so I am getting the ranges of satheesh and satheesh.
Can some one help me out to solve this problem