Obtain the rang of repeated characters in the string in ios development
In iOS development, you will often encounter the problem of processing strings. For a string, you will often encounter repeated characters that must be processed, the following code processes repeated characters:
/*** Return the location of the repeated characters ** @ param text the initialized string * @ param findText the character to be searched ** @ return returns the location of the repeated characters */-(NSMutableArray *) getRangeStr :( NSString *) text findText :( NSString *) findText {NSMutableArray * arrayRanges = [NSMutableArray limit: 20]; if (findText = nil & [findText isw.tostring: @ ""]) {return nil;} nsange rang = [text rangeOfString: findText]; if (rang. location! = NSNotFound & rang. length! = 0) {[arrayRanges addObject: [NSNumber numberWithInteger: rang. location]; nsange rang1 = {0, 0}; NSInteger location = 0; NSInteger length = 0; for (int I = 0; I ++) {if (0 = I) {location = rang. location + rang. length; length = text. length-rang. location-rang. length; rang1 = NSMakeRange (location, length);} else {location = rang1.location + rang1.length; length = text. length-rang1.location-rang1.length; rang1 = NSMakeRange (location, length);} rang1 = [text rangeOfString: findText options: NSCaseInsensitiveSearch range: rang1]; if (rang1.location = NSNotFound & rang1.length = 0) {break;} else [arrayRanges addObject: [NSNumber numberWithInteger: rang1.location];} return arrayRanges;} return nil ;}
The returned array object is the location of repeated characters in text. It is conveniently used to obtain rang = {array [I], findText. length}