using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Xml;
namespace Task_3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// Opens File and executes code to show how many duplicates there are
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
{
//Set up streamreader
StreamReader reader;
//Create filter for txt files
openFileDialog1.Filter = "Text Document|*.txt|All Files|*.*";
//List to store all names
List
<string> namesList
= new List
<string> ();
//List to store duplicate names
List
<string> duplicateCheckList
= new List
<string>();
//Try catch for input
try
{
//If ok is pressed
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
//Reads file
reader = File.OpenText(openFileDialog1.FileName);
//Try catch for input
try
{
//Execute until the end of stream
while (!reader.EndOfStream)
{
//Reads each line and stores into 2 lists and displays the name
string line = reader.ReadLine();
namesList.Add(line);
duplicateCheckList.Add(line);
listBoxAllNames.Items.Add(line);
}
//Set a counter for number of duplicates
int counter = 0;
//Goes through each name is original list
foreach (string iNameList in namesList)
{
//Goes through each name in duplicate list
foreach (string iDuplicateCheck in duplicateCheckList)
{
//Checks if the original name list matches the duplicate list
if (iNameList == iDuplicateCheck)
{
//Counts the duplicate
counter++;
}
}
//Checks if a duplication has occured
if (counter != 0)
{
//Displays the dupliacte items with the number of duplicates
listBoxDuplicates.Items.Add(iNameList + ": " + counter);
}
//Removes all the duplicates from the duplicated list so it doesn't get show again
duplicateCheckList.RemoveAll(x => x == iNameList);
//Set counter to 0 for next
counter = 0;
}
}
catch (Exception ex)
{
//Displays error message
MessageBox.Show(ex.Message);
//Clears listboxes
listBoxAllNames.Items.Clear();
listBoxDuplicates.Items.Clear();
}
}
}
catch (Exception ex)
{
//Displays error message
MessageBox.Show(ex.Message
);
//Clears listboxes
listBoxAllNames.Items.Clear ();
listBoxDuplicates.Items.Clear();
}
}
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}