private static string ConvertText(string text, Language layout) //Перекодирование текста { const string RusKey = "Ё!\"№;%:?*()_+ЙЦУКЕНГШЩЗХЪ/ФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,ё1234567890-=йцукенгшщзхъ\\фывапролджэячсмитьбю. "; const string EngKey = "~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./ "; string str = ""; switch (layout) { case Language.ru_RU: foreach (char c in text) { try { str += EngKey.Substring(RusKey.IndexOf(c), 1); } catch { str += c; } } break; case Language.en_US: foreach (char c in text) { try { str += RusKey.Substring(EngKey.IndexOf(c), 1); } catch { str += c; } } break; default: str = text; break; } return(str); }
private string TextConverter(string text, CultureInfo layout) { const string RusKey = "Ё!\"№;%:?*()_+ЙЦУКЕНГШЩЗХЪ/ФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,ё1234567890-=йцукенгшщзхъ\\фывапролджэячсмитьбю. "; const string EngKey = "~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./ "; string str = ""; if (layout.Equals(new CultureInfo("ru-RU"))) { foreach (char c in text) { try { str += EngKey.Substring(RusKey.IndexOf(c), 1); } catch { str += c; } } } else if (layout.Equals(new CultureInfo("en-US"))) { foreach (char c in text) { try { str += RusKey.Substring(EngKey.IndexOf(c), 1); } catch { str += c; } } } else { str = text; } return(str); }