gpt4 book ai didi

c# - iOS-Unicode取消签名

转载 作者:行者123 更新时间:2023-12-01 19:13:00 25 4
gpt4 key购买 nike

我有一个用C#编写的函数,我想将其转换为Objective-C。怎么做?

public static string UnicodeUnSign(string s)
{
const string uniChars = "àáảãạâầấẩẫậăằắẳẵặèéẻẽẹêềếểễệđìíỉĩịòóỏõọôồốổỗộơờớởỡợùúủũụưừứửữựỳýỷỹỵÀÁẢÃẠÂẦẤẨẪẬĂẰẮẲẴẶÈÉẺẼẸÊỀẾỂỄỆĐÌÍỈĨỊÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÙÚỦŨỤƯỪỨỬỮỰỲÝỶỸỴÂĂĐÔƠƯ";
const string koDauChars = "aaaaaaaaaaaaaaaaaeeeeeeeeeeediiiiiooooooooooooooooouuuuuuuuuuuyyyyyAAAAAAAAAAAAAAAAAEEEEEEEEEEEDIIIOOOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYYAADOOU";

if (string.IsNullOrEmpty(s))
{
return s;
}

string retVal = String.Empty;
for (int i = 0; i < s.Length; i++)
{
int pos = uniChars.IndexOf(s[i].ToString());
if (pos >= 0)
retVal += koDauChars[pos];
else
retVal += s[i];
}
return retVal;
}

最佳答案

您可以使用CoreFoundation CFStringTransform函数,该函数执行列表中几乎所有的转换。只有“đ”和“Đ”必须分开处理:

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;
}

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

关于c# - iOS-Unicode取消签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15153908/

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