gpt4 book ai didi

objective-c - NSString - 仅转换为纯字母表(即删除重音符号+标点符号)

转载 作者:太空狗 更新时间:2023-10-30 03:10:31 28 4
gpt4 key购买 nike

我正在尝试比较没有任何标点符号、空格、重音符号等的名称。目前我正在做以下事情:

-(NSString*) prepareString:(NSString*)a {
//remove any accents and punctuation;
a=[[[NSString alloc] initWithData:[a dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES] encoding:NSASCIIStringEncoding] autorelease];

a=[a stringByReplacingOccurrencesOfString:@" " withString:@""];
a=[a stringByReplacingOccurrencesOfString:@"'" withString:@""];
a=[a stringByReplacingOccurrencesOfString:@"`" withString:@""];
a=[a stringByReplacingOccurrencesOfString:@"-" withString:@""];
a=[a stringByReplacingOccurrencesOfString:@"_" withString:@""];
a=[a lowercaseString];
return a;
}

但是,我需要为数百个字符串执行此操作,并且我需要提高效率。有什么想法吗?

最佳答案

NSString* finish = [[start componentsSeparatedByCharactersInSet:[[NSCharacterSet letterCharacterSet] invertedSet]] componentsJoinedByString:@""];

关于objective-c - NSString - 仅转换为纯字母表(即删除重音符号+标点符号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1231764/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com