开发者

.NET String Encoding - Character Converting

开发者 https://www.devze.com 2023-03-21 02:37 出处:网络
I have a string v开发者_Go百科ariable that stores a text in Turkish language string str = \"açğş\";

I have a string v开发者_Go百科ariable that stores a text in Turkish language

string str = "açğş";

I want to convert each character of this string to appropriate English Letter.

So that the conversion must be like: , açğş --> acgs

How can I do it using .NET/C# ?


From one of Jeff Atwood's original posts on URL purifying, they call RemapInternationalCharToAscii. please check that/those post(s) out, as I believe they are a great solution (and, given it's Jeff Atwood ♦ speed has been taken in to consideration).


string[] notAccpetedA = new string[] {"ã","ä"};
string mystring = "ãçğş";
foreach(string _char in notAcceptedA)
{
mystring.Replace(_char,"a");
}


Easiest way: str = str.Replace("ç", "c").Replace("ğ", "g").Replace("Ç", "C")....;


1- use Dictionary<char,string> Dic= new Dictionary<char,string>();

2- populate the dictionary with Translation letters

3- strOut =String.Join("", StrIn.ToCharArray().Select(C=>Dic.ContainsKey(C)?Dic[C]:C.ToString()).ToArray());

0

精彩评论

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

关注公众号