Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace Final_PRoject
  13. {
  14. public partial class Form1 : Form
  15. {
  16. StreamReader reader;
  17. StreamWriter writer;
  18. int choice;
  19. public Form1()
  20. {
  21. InitializeComponent();
  22. }
  23.  
  24. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  25. {
  26. string str = (string)comboBox1.SelectedItem;
  27. if(str == "Display")
  28. {
  29. choice = 1;
  30. }
  31. else if(str == "Replace")
  32. {
  33. choice = 2;
  34. }
  35. else if(str == "Count")
  36. {
  37. choice = 3;
  38. }
  39. else if(str == "Convert")
  40. {
  41. choice = 4;
  42. }
  43. else if(str == "Remove Spaces")
  44. {
  45. choice = 5;
  46. }
  47. else if(str == "Print Sentence")
  48. {
  49. choice = 6;
  50. }
  51. }
  52.  
  53. private void button1_Click(object sender, EventArgs e)
  54. {
  55. reader = new StreamReader(@"C:\Users\Elijah Gulle\Documents\Mapua\1st Year\1st Year, 4th Term\CS128-2\Opn ur ays\Open your Eyes.txt");
  56. if(choice == 1)
  57. {
  58. textBox1.Text = reader.ReadToEnd();
  59. }
  60. else if(choice == 2)
  61. {
  62. string s = reader.ReadToEnd();
  63. string s1 = textBox2.Text;
  64. string s2 = textBox3.Text;
  65. string s3 = s.Replace(s1, s2);
  66. textBox1.Text = s3;
  67. }
  68. else if(choice == 3)
  69. {
  70. string s = reader.ReadToEnd();
  71. string s1 = textBox2.Text;
  72. int count = 0;
  73. int i = 0;
  74. while((i = s.IndexOf(s1, i)) != -1)
  75. {
  76. i += s1.Length;
  77. count++;
  78. }
  79. textBox1.Text = "There are " + count.ToString() + " occurences of the specified word in the .txt file";
  80. }
  81. else if(choice == 4)
  82. {
  83. string s = reader.ReadToEnd();
  84. s = s.ToUpper();
  85. textBox1.Text = s;
  86. }
  87. else if(choice == 5)
  88. {
  89. string s = reader.ReadToEnd();
  90. string s1 = s.Replace(" ", "");
  91. textBox1.Text = s1;
  92. }
  93. else if(choice == 6)
  94. {
  95. textBox1.Clear();
  96. string searchkeyword = textBox2.Text;
  97. 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");
  98. List<string> results = new List<string>();
  99.  
  100. foreach (string line in textlines)
  101. {
  102. if(line.Contains(searchkeyword))
  103. {
  104. results.Add(line);
  105. textBox1.Text += line + "\r\n";
  106. }
  107. }
  108. }
  109. reader.Close();
  110. }
  111.  
  112. private void button2_Click(object sender, EventArgs e)
  113. {
  114. 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");
  115. writer.WriteLine(textBox1.Text);
  116. MessageBox.Show("File has been saved.");
  117. writer.Close();
  118. }
  119.  
  120. private void textBox1_TextChanged(object sender, EventArgs e)
  121. {
  122. textBox1.ScrollBars = ScrollBars.Vertical;
  123. }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement