objective c - Getting word from string in iOS -


i getting string separately in loop -> inbox, [gmail]/all mail or [gmail acc]/trash

i want find here substring like -> inbox, mail or trash , add array(folderarray).

by seeing above words, there strings -> [gmail]/,[gmail acc]/ etc. coming unnecessarily , want remove them if such strings appear , words -> inbox, mail, trash

i tried below code doesn't give me word expected following link sample string separator

could me solve please?

for (mcoimapfolder *fdr in folders) {      nsstring *foldertitle = fdr.path; // gives inbox, [gmail]/all mail or [gmail acc]/trash     (int i=0; i<[folderlist.defaultfolderarray count];i++) {          if ([foldertitle rangeofstring:[folderlist.defaultfolderarray objectatindex:i] options:nscaseinsensitivesearch].location != nsnotfound) {             nslog(@"yes contain word");              nsrange range = [foldertitle rangeofstring:[folderlist.defaultfolderarray objectatindex:i] options:nscaseinsensitivesearch];             if (range.length>1) {                 foldertitle = [[foldertitle substringfromindex:nsmaxrange(range)] stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]];             }             break;         }     }     [folderarray addobject:foldertitle]; }   - (nsarray *) defaultfolderarray {     _defaultfolderarray = [nsarray arraywithobjects:@"inbox", @"draft", @"sent", @"spam", @"trash", nil];      return _defaultfolderarray; } 

edited regular expression

nsstring *string = @"[anything]/blabla"; nsregularexpression *regex = [nsregularexpression regularexpressionwithpattern:@".*[^ a-z0-9\(\)]+" options:0 error:nil]; nstextcheckingresult *match = [regex firstmatchinstring:string options:0 range:nsmakerange(0, [string length])]; if(match.range.length > 0) {     nsstring *newstring = [string substringfromindex:match.range.length]; } 

the regex analyze string until last special character (except space character, since want keep space in names of folders).

i think can trick.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -