Удалить в строке все слова заданной длины - C#
Формулировка задачи:
С клавиатуры вводится строчка.
1.Удалить все слова в строке заданной длины
Решение задачи: «Удалить в строке все слова заданной длины»
textual
Листинг программы
using System;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
public class Program
{
private static void Main()
{
var input = Console.ReadLine();
var length = Convert.ToInt32(Console.ReadLine());
if (!string.IsNullOrEmpty(input) && length>0)
{
var output = Regex.Replace(input, "\\b[\\w]{" + length + "}\\b", string.Empty, RegexOptions.Compiled);
Console.WriteLine("Без слов заданной длины: {0}", output);
}
Console.ReadKey();
}
}
}