简体   繁体   中英

How to remove the Special character in iPhone?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM