本文介绍了删除NSString中的特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将段落转换为单词,其中包含许多特殊字符,例如
i am convert paragraph into words it contains many special characters like
" , " . `
如何在nsstring中删除此字符并仅在nsstring中获取字母
how to remove this characters in nsstring and get only alphabets in nsstring
ex新"到新的//the special characters are change
推荐答案
NSString *unfilteredString = @"!@#$%^&*()_+|abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
NSCharacterSet *notAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"] invertedSet];
NSString *resultString = [[unfilteredString componentsSeparatedByCharactersInSet:notAllowedChars] componentsJoinedByString:@""];
NSLog (@"Result: %@", resultString);
请尝试一下可能会帮助您
TRY THIS IT MAY HELPS YOU
这篇关于删除NSString中的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!