IOS - Unicode Unsign

前端 未结 2 655
心在旅途
心在旅途 2021-01-24 02:29

I have a function written in C#, i want to convert it to objective-c. How to do it?

public static string UnicodeUnSign(string s)
{
    const string uniChars = \"         


        
2条回答
  •  天涯浪人
    2021-01-24 03:25

    You could use the CoreFoundation CFStringTransform function which does almost all transformations from your list. Only "đ" and "Đ" have to be handled separately:

    NSString *UnicodeUnsign(NSString *s)
    {
        NSMutableString *result = [s mutableCopy];
        // __bridge only required if you compile with ARC:
        CFStringTransform((__bridge CFMutableStringRef)result, NULL, kCFStringTransformStripCombiningMarks, NO);
    
        [result replaceOccurrencesOfString:@"đ" withString:@"d" options:0 range:NSMakeRange(0, [result length])];
        [result replaceOccurrencesOfString:@"Đ" withString:@"D" options:0 range:NSMakeRange(0, [result length])];
    
        return result;
    }
    

    Example:

    NSString *input = @"Hễllö Wõrld! - ếểễệđìíỉĩịòó";
    NSString *output = UnicodeUnsign(input);
    NSLog(@"%@", output);
    // Output: Hello World! - eeeediiiiioo
    

提交回复
热议问题