Hello, I want to make a program that reads text from a file and displays only those sentences that are made up of a specified number of words.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Stroki { class Program { static void Main() { string[] NewFile = File.ReadAllLines(@"полный адрес файла"); foreach (string str in NewFile)//считывает весь файл? { Console.WriteLine(str);//вывело строки файла } Console.Write("Введите количество слов = "); string buf = Console.ReadLine(); int n = int.Parse(buf); //тут фором пробегаемся посимвольно по строкам и находим разделительные знаки или пробелы.count++ //условие(если count в строке равен указаному вначале n,то выводим необходимое предложение или несколько,если они одинаковы по количеству слов в предложении) Console.ReadKey(); } } } Sample file:
Корова,мясо,трава,луга. Экзамены,зачёты,курсовые. Лето,зима. PS What if all the sentences are in one line?