Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Курсовая.txt.docx
Скачиваний:
2
Добавлен:
18.09.2019
Размер:
229.37 Кб
Скачать
  1. Текст программы

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

using System.IO;

namespace WPFExampleProject

{

/// <summary>

/// Interaction logic for MainWindow.xaml

/// </summary>

public partial class MainWindow : Window

{

protected String text;

public MainWindow()

{

InitializeComponent();

}

private void button1_Click(object sender, RoutedEventArgs e)

{

Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

dlg.FileName = "Document";

dlg.DefaultExt = "*.log";

dlg.Filter = "Natalia's Files (.log)|*.log";

Nullable<bool> result = dlg.ShowDialog();

if (result == true)

{

string filename = dlg.FileName;

StreamReader sr = new StreamReader(filename, Encoding.Default);

text = sr.ReadToEnd();

textBox2.Text = text;

sr.Close();

}

}

public void Max()

{

string[] TextArray = text.Split(' ', '.', ',', '!', '?', '"', '-', '_', ')', '(', '\n');

int maxValue = TextArray[0].Length;

String maxWord = TextArray[0];

for (int i = 1; i < TextArray.Length; i++)

{

if (maxValue < TextArray[i].Length)

maxValue = TextArray[i].Length;

}

textBox1.Text = "";

for (int i = 0; i < TextArray.Length; i++)

{

if (maxValue == TextArray[i].Length)

textBox1.Text += TextArray[i];

}

}

public void Min()

{

string[] TextArray = text.Split('\n', ' ', '.', ',', '!', '?', '"', '-', '—', '_', ')', '(');

int minValue = TextArray[0].Length;

String minWord = TextArray[0];

for (int i = 1; i < TextArray.Length; i++)

{

if (minValue > TextArray[i].Length && TextArray[i].Length != 0)

minValue = TextArray[i].Length;

}

textBox1.Text = "";

for (int i = 0; i < TextArray.Length; i++)

{

if (minValue == TextArray[i].Length)

textBox1.Text += TextArray[i] + "\n";

}

}

public void quote

{

textBox1.Text = "";

bool blocked = false;

char symbol = '"';

char[] delimiter = text.ToCharArray();

foreach (char b in delimiter)

{

if ((b.CompareTo(symbol)==0) && blocked == false)

{

MessageBox.Show("!!!!");

blocked = true;

continue;

}

if (b == symbol && blocked == true)

{

textBox1.Text += "\n";

blocked = false;

continue;

}

if (blocked == true)

textBox1.Text += b;

}

}

public void Glasn

{

try

{

textBox1.Text = "";

string[] TextArray = text.Split(' ');

char[] GlasnArray = { 'а', 'е', 'ё', 'и', 'о', 'у', 'ы', 'э', 'ю', 'я' };

foreach (string b in TextArray)

{

string c;

c = b.ToLower();

char[] B = b.ToCharArray();

foreach (char exp in GlasnArray)

{

if (B[0].CompareTo(exp) == 0)

{

textBox1.Text += b + "\n";

}

}

}

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

}

private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)

{

String currentItemText = listBox1.SelectedValue.ToString();

int currentItemIndex = listBox1.SelectedIndex;

if (currentItemIndex == 0)

{

Max();

}

if (currentItemIndex == 1)

{

Min();

}

if (currentItemIndex == 2)

{

quote();

}

if (currentItemIndex == 3)

{

Glasn();

}

if (currentItemIndex == 4)

{

Pred();

}

}

public void Pred

{

textBox1.Text = "";

int n;

n = Convert.ToInt32(textBox3.Text);

string[] TextArray = text.Split('.', '!', '?');

foreach (string b in TextArray)

{

if (b.Split(' ').Length == n)

{

textBox1.Text += b + "\n";

}

}

}

}

}