nsmutablestring * Mutstr = [nsmutablestring stringwithstring:@ "AAABBBBAAACCC"]; NSString * str = @ "a"; Nsrange range = {0,mutstr.length}; [Mutstr replaceoccurrencesofstring:@ "" withstring:@ "" Options:nsliteralsearch Range:range]; [Mutstr replaceoccurrencesofstring:@ "\ n" withstring:@ "" Options:nsliteralsearch Range:range]; nsmutableattributedstring * attr = [[nsmutableattributedstring alloc]initwithstring:mutstr]; Nserror * ERROR; Nsregularexpression * Express = [nsregularexpression regularexpressionwithpattern:str options: Nsregularexpressioncaseinsensitive error:&error]; Nsarray<nstextcheckingresult *> * result = [Express matchesinstring:mutstr options:0 Range:range]; For (Nstextcheckingresult * match in result) {Nsrange range = [Match range]; [attr addattribute:nsforegroundcolorattributename Value:[uicolor Redcolor] range:range]; } UILabel * lbl = [[UILabel alloc]initwithframe:cgrectmake (100, 100, 200, 40)]; [SELf.view ADDSUBVIEW:LBL]; Lbl.textcolor = [Uicolor Bluecolor]; Lbl.attributedtext = attr;
IOS marks all characters in a string of characters