private void button1_Click(object sender, EventArgs e) { StreamReader myStream = null; OpenFileDialog openFileDialog2 = new OpenFileDialog(); openFileDialog2.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog2.FilterIndex = 2; openFileDialog2.RestoreDirectory = true; if (openFileDialog2.ShowDialog() == DialogResult.OK) { textToFindStatistic = new LetterStatistic("Language to find"); try { myStream = new StreamReader(openFileDialog2.FileName, Encoding.Default); char previousLetter = ' '; do { var ch = (char)myStream.Read(); textToFindStatistic.Count(ch, previousLetter); previousLetter = ch; }while (!myStream.EndOfStream); CompareLanguage(); } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } }
public FindLanguage(List <LetterStatistic> statistic) { InitializeComponent(); StatisticList = statistic; comboBoxMode.Items.Add("All letters"); comboBoxMode.Items.Add("First letters"); comboBoxMode.Items.Add("Last letters"); comboBoxMode.SelectedIndex = 0; textToFindStatistic = new LetterStatistic("Language to find"); }
private List <LetterNr> GetLetters(LetterStatistic selectedLanguage) { if (comboBoxMode.Items.Count > 0) { var mode = comboBoxMode.SelectedItem.ToString(); if (mode == "All letters") { return(selectedLanguage.AllOrderLetters()); } if (mode == "First letters") { return(selectedLanguage.FirstOrderLetters()); } if (mode == "Last letters") { return(selectedLanguage.LastOrderLetters()); } } return(new List <LetterNr>()); }
private long GetNrLetters(LetterStatistic selectedLanguage) { if (comboBoxMode.Items.Count > 0) { var mode = comboBoxMode.SelectedItem.ToString(); if (mode == "All letters") { return(selectedLanguage.NrLetters); } if (mode == "First letters") { return(selectedLanguage.NrFirstLetters); } if (mode == "Last letters") { return(selectedLanguage.NrLastLetters); } } return(0); }