Консоль - работа со строками - C#
Формулировка задачи:
Доброго времени суток! Помогите разобраться с проблемой (Необработанное исключение типа "System.IndexOutOfRangeException")
вот код:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Задание: Удалить все русские буквы из строки");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Введите строку:");
Console.ForegroundColor = ConsoleColor.Yellow;
string strV = Console.ReadLine();
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("========================================================");
Console.WriteLine();
int c = strV.Length; //попытка исправить ошибку
for (int i = 0; i <= c; i++)
for(char sim = 'а'; sim <= 'я'; sim++)
if (strV[i] == sim)
{
strV = strV.Remove(i, 1);
i = 0;
c--;
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Преобразованная строка:");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(strV);
Console.ReadKey();Решение задачи: «Консоль - работа со строками»
textual
Листинг программы
int c = strV.Length;
string rus = "абвгдеёжзийклмнопрстуфхцчшщьъыэюя";
for (int i = c - 1; i >= 0; i--)
{
if (rus.Contains(Char.ToLower(strV[i])))
{
strV = strV.Remove(i, 1);
}
}