gpt4 book ai didi

iphone - 替换特殊字符的问题

转载 作者:行者123 更新时间:2023-12-03 20:20:05 24 4
gpt4 key购买 nike

我在从字符串中删除特殊字符时遇到问题。我使用了以下代码。但是没有用。请建议我更好的逻辑

- (NSString *)trimmedReciString:(NSString *)stringName 
{
NSCharacterSet *myCharSet = [NSCharacterSet characterSetWithCharactersInString:@"-/:;()$&@\".,?!\'[]{}#%^*+=_|~<>€£¥•."];
for (int i = 0; i < [stringName length]; i++) {
unichar c = [stringName characterAtIndex:i];
if ([myCharSet characterIsMember:c]) {
NSLog(@"%@",[NSString stringWithFormat:@"%c",[stringName characterAtIndex:i]]);
stringName = [stringName stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%c",[stringName characterAtIndex:i]] withString:@""];

}
}
return stringName;
}

最佳答案

NSString *s = @"$$$hgh$g%k&fg$$tw/-tg";
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"-/:;()$&@\".,?!\'[]{}#%^*+=_|~<>€£¥•."];
s = [[s componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
NSLog(@"String is: %@", s);

关于iphone - 替换特殊字符的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13487931/

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