Как узнать, запомнить регистр и в последствии с этим изменить символ в c#?

я делаю программку, которая будет изменять текст с английской раскладки на русскую.

Написал код, и он работает, но есть одна проблема, он не переводил на русскую раскладку Большие буквы. Поэтому привел всю строку к нижнему регистру.

using System;

namespace EnlToRus
{
    class Program
    {
        static void Main(string[] args)
        {
            string textEn = Console.ReadLine();
            textEn = textEn.ToLower();
            Char[] textCharsEn = textEn.ToCharArray();
            int timer = 0;
            foreach (var item in textCharsEn)
            {
                switch (item)
                {
                    case 'q':
                        textCharsEn[timer] = 'й';
                        break;
                    case 'w':
                        textCharsEn[timer] = 'ц';
                        break;
                    case 'e':
                        textCharsEn[timer] = 'у';
                        break;
                    case 'r':
                        textCharsEn[timer] = 'к';
                        break;
                    case 't':
                        textCharsEn[timer] = 'е';
                        break;
                    case 'y':
                        textCharsEn[timer] = 'н';
                        break;
                    case 'u':
                        textCharsEn[timer] = 'г';
                        break;
                    case 'i':
                        textCharsEn[timer] = 'ш';
                        break;
                    case 'o':
                        textCharsEn[timer] = 'щ';
                        break;
                    case 'p':
                        textCharsEn[timer] = 'з';
                        break;
                    case '[':
                        textCharsEn[timer] = 'х';
                        break;
                    case ']':
                        textCharsEn[timer] = 'ъ';
                        break;
                    case 'a':
                        textCharsEn[timer] = 'ф';
                        break;
                    case 's':
                        textCharsEn[timer] = 'ы';
                        break;
                    case 'd':
                        textCharsEn[timer] = 'в';
                        break;
                    case 'f':
                        textCharsEn[timer] = 'а';
                        break;
                    case 'g':
                        textCharsEn[timer] = 'п';
                        break;
                    case 'h':
                        textCharsEn[timer] = 'р';
                        break;
                    case 'j':
                        textCharsEn[timer] = 'о';
                        break;
                    case 'k':
                        textCharsEn[timer] = 'л';
                        break;
                    case 'l':
                        textCharsEn[timer] = 'д';
                        break;
                    case ';':
                        textCharsEn[timer] = 'ж';
                        break;
                    case 'z':
                        textCharsEn[timer] = 'я';
                        break;
                    case 'x':
                        textCharsEn[timer] = 'ч';
                        break;
                    case 'c':
                        textCharsEn[timer] = 'с';
                        break;
                    case 'v':
                        textCharsEn[timer] = 'м';
                        break;
                    case 'b':
                        textCharsEn[timer] = 'и';
                        break;
                    case 'n':
                        textCharsEn[timer] = 'т';
                        break;
                    case 'm':
                        textCharsEn[timer] = 'ь';
                        break;
                    case ',':
                        textCharsEn[timer] = 'б';
                        break;
                    case '.':
                        textCharsEn[timer] = 'ю';
                        break;
                    case '?':
                        textCharsEn[timer] = ',';
                        break;
                    case '/':
                        textCharsEn[timer] = '.';
                        break;
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                    case '0':
                        textCharsEn[timer] = item;
                        break;
                    case ' ':
                        textCharsEn[timer] = item;
                        break;
                }
                timer++;
            }
            foreach (var item in textCharsEn)
            {
                Console.Write(item);
            }
        }
    }
}

Тут вытекает вопрос, есть ли способ проверять регистр и в зависимости от этого уже изменять символ? Или нужно полностью вручную для каждого символа писать два кейса с верхним и нижним регистром?


Ответы (0 шт):