//метод очистки private void ClearMethod() { InputCodeTextBox.Clear(); OutputCodeTextBox.Clear(); InputDecodeTextBox.Clear(); OutputDecodeTextBox.Clear(); KF.Clear(); }
//кнопка "закодировать" private void CodeButton_Click(object sender, RoutedEventArgs e) { try { string str1 = InputCodeTextBox.Text, str = ""; OutputCodeTextBox.Clear(); if (str1 == String.Empty) { throw new Exception("Пустая входная строка!"); } int count = 1; char current = str1[0]; if (char.IsDigit(current)) { MessageBox.Show("Введён некорректный текст!"); } else { for (int i = 1; i < str1.Length; i++) { char c = str1[str1.Length - 1]; if (char.IsDigit(c)) { MessageBox.Show("Введён некорректный текст!"); return; } else { if (current == str1[i]) { count++; } else if (count != 1) { str += Convert.ToString(count) + Convert.ToString(current); count = 1; current = str1[i]; } else { str += Convert.ToString(current); current = str1[i]; } } } if (!char.IsDigit(current)) { if (count != 1) { str += Convert.ToString(count) + Convert.ToString(current); } else { str += Convert.ToString(current); } OutputCodeTextBox.Text = str; double kf = (double)str1.Length / str.Length; KF.Text = kf.ToString(CultureInfo.InvariantCulture); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }