Windows Form С#
Написать программу, которая считывает английский текст из файла и выводит на экран слова текста, начинающиеся и оканчивающиеся на гласные буквы.

Ответы

Ответ дал: ЯковПервый
1

// Поскольку указание расположения файла не требовалось, файл с текстом должен находиться в папке с .exe файлом и называться input.txt

namespace WinFormsApp2

{

   public partial class Form1 : Form

   {

       public Form1()

       {

           InitializeComponent();

       }

       private void ParseFileBtn_Click(object sender, EventArgs e)

       {

           if (!TryReadTextFromFile(out string text))

           {

               MessageBox.Show("Failed to read file.");

               return;

           }

           if (string.IsNullOrEmpty(text) || string.IsNullOrWhiteSpace(text))

           {

               MessageBox.Show("File is empty.");

               return;

           }

           string vowelLetters = "aAeEiIoOuUyY";

           string[] words = text

               .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)

               .Where(t => vowelLetters.Contains(t.First()) && vowelLetters.Contains(t.Last()))

               .ToArray();

           InfoListBox.Items.Clear();

           if (words.Length == 0)

           {

               MessageBox.Show("Nothing found.");

               return;

           }

           foreach (var w in words)

               InfoListBox.Items.Add(w);

       }

       private bool TryReadTextFromFile(out string text)

       {

           try

           {

               text = File.ReadAllText("input.txt");

               return true;

           }

           catch

           {

               text = null;

               return false;

           }

       }

   }

}

Приложения:

esstry: https://znanija.com/task/48338567 Поможешь?
Вас заинтересует