Exemple #1
0
        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);
                }
            }
        }
Exemple #2
0
        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");
        }
Exemple #3
0
 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>());
 }
Exemple #4
0
 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);
 }