NSString - Convert to pure alphabet only (i.e. remove accents+punctuation)

前端 未结 13 1399
暖寄归人
暖寄归人 2020-12-02 15:49

I\'m trying to compare names without any punctuation, spaces, accents etc. At the moment I am doing the following:

-(NSString*) prepareString:(NSString*)a {
         


        
13条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 16:26

    Consider using the RegexKit framework. You could do something like:

    NSString *searchString      = @"This is neat.";
    NSString *regexString       = @"[\W]";
    NSString *replaceWithString = @"";
    NSString *replacedString    = [searchString stringByReplacingOccurrencesOfRegex:regexString withString:replaceWithString];
    
    NSLog (@"%@", replacedString);
    //... Thisisneat
    

提交回复
热议问题