Obtain the rang of repeated characters in the string in ios development

Source: Internet
Author: User

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}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.