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 = "àáảãạâầấẩẫậăằắẳẵặèéẻẽẹêềếểễệđìíỉĩịòóỏõọôồốổỗộơờớởỡợùúủũụưừứửữựỳýỷỹỵÀÁẢÃẠÂẦẤẨẪẬĂẰẮẲẴẶÈÉẺẼẸÊỀẾỂỄỆĐÌÍỈĨỊÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÙÚỦŨỤƯỪỨỬỮỰỲÝỶỸỴÂĂĐÔƠƯ";
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;
}
You could use the CoreFoundation
CFStringTransform
function which does almost all transformations from your list. Only "đ" and "Đ" have to be handled separately:Example:
Without resorting to core foundation: