Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- namespace Final_PRoject
- {
- public partial class Form1 : Form
- {
- StreamReader reader;
- StreamWriter writer;
- int choice;
- public Form1()
- {
- InitializeComponent();
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- string str = (string)comboBox1.SelectedItem;
- if(str == "Display")
- {
- choice = 1;
- }
- else if(str == "Replace")
- {
- choice = 2;
- }
- else if(str == "Count")
- {
- choice = 3;
- }
- else if(str == "Convert")
- {
- choice = 4;
- }
- else if(str == "Remove Spaces")
- {
- choice = 5;
- }
- else if(str == "Print Sentence")
- {
- choice = 6;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- reader = new StreamReader(@"C:\Users\Elijah Gulle\Documents\Mapua\1st Year\1st Year, 4th Term\CS128-2\Opn ur ays\Open your Eyes.txt");
- if(choice == 1)
- {
- textBox1.Text = reader.ReadToEnd();
- }
- else if(choice == 2)
- {
- string s = reader.ReadToEnd();
- string s1 = textBox2.Text;
- string s2 = textBox3.Text;
- string s3 = s.Replace(s1, s2);
- textBox1.Text = s3;
- }
- else if(choice == 3)
- {
- string s = reader.ReadToEnd();
- string s1 = textBox2.Text;
- int count = 0;
- int i = 0;
- while((i = s.IndexOf(s1, i)) != -1)
- {
- i += s1.Length;
- count++;
- }
- textBox1.Text = "There are " + count.ToString() + " occurences of the specified word in the .txt file";
- }
- else if(choice == 4)
- {
- string s = reader.ReadToEnd();
- s = s.ToUpper();
- textBox1.Text = s;
- }
- else if(choice == 5)
- {
- string s = reader.ReadToEnd();
- string s1 = s.Replace(" ", "");
- textBox1.Text = s1;
- }
- else if(choice == 6)
- {
- textBox1.Clear();
- string searchkeyword = textBox2.Text;
- string[] textlines = File.ReadAllLines(@"C:\Users\Elijah Gulle\Documents\Mapua\1st Year\1st Year, 4th Term\CS128-2\Opn ur ays\Open your Eyes.txt");
- List<string> results = new List<string>();
- foreach (string line in textlines)
- {
- if(line.Contains(searchkeyword))
- {
- results.Add(line);
- textBox1.Text += line + "\r\n";
- }
- }
- }
- reader.Close();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- writer = new StreamWriter(@"C:\Users\Elijah Gulle\Documents\Mapua\1st Year\1st Year, 4th Term\CS128-2\Opn ur ays\Open your Eyes Update.txt");
- writer.WriteLine(textBox1.Text);
- MessageBox.Show("File has been saved.");
- writer.Close();
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- textBox1.ScrollBars = ScrollBars.Vertical;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement