开发者

How to remove the Special character in iPhone?

开发者 https://www.devze.com 2023-04-03 03:35 出处:网络
I have used web service and get the response in the XML format, after that i have used xml parsing for parsed contents, but i getı: ürsekün 开发者_如何转开发etc., SO i want to remove that spe

I have used web service and get the response in the XML format, after that i have used xml parsing for parsed contents, but i get ı: ürse kün 开发者_如何转开发etc., SO i want to remove that special characters and i have used NSUTF8StringEncoding and NSASCIIStringEncoding. But it doesn't work, so please give help me out?.


Either what you have is binary data, or you have a string in some encoding that's not UTF-8. Assuming it's the latter, you need to figure out what that encoding is, which is entirely dependent on the data, what it is, and where it came from.


TESTED CODE: 100 % WORKS

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];

NSString *input = @"ı: ürse kün";


NSString *folded = [input stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:locale];


NSLog(@"resulted String is - %@",folded);

OUTPUT:

    resulted String is - A±: A¼rse kA¼n

OR

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];

NSString *input = @"ı: ürse kün vijay 12344";

input = [input decomposedStringWithCompatibilityMapping];


NSString *output=[input stringByTrimmingCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ0123456789"] invertedSet]];


NSString *folded = [output stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:locale];


NSLog(@"resulted String is :%@",folded);

OUTPUT:

resulted String is :A±: A1⁄4rse kA1⁄4n vijay 12344
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号