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 Simple_File_Demo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { listBox1.Items.Clear(); string line; OpenFileDialog ofd = new OpenFileDialog(); ofd.DefaultExt = "txt"; ofd.ShowDialog(); StreamReader sr = new StreamReader(ofd.FileName); while (sr.Peek() > 0) { line = sr.ReadLine(); listBox1.Items.Add(line); } sr.Close(); }
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; //David Crandall //October 22nd, 2015 //This program counts the letters for each inputed phrase namespace Letter_Counter { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnCount_Click(object sender, EventArgs e) { lstbxCounted.Items.Clear(); //establishes variables that will be used later string myData = txtPhrase.Text.ToUpper(); string Letters = ""; string temp; int Count = 0; //This array will allow the counting of letters int [] intz = new int[26]; //Removes everything that is a non-letters for (int i = 0; i < 26; i++) { intz[i] = 0; } for (int i = 0; i < myData.Length; i++) { temp = myData.Substring(i, 1); if (temp.CompareTo("A") >= 0 && temp.CompareTo("Z") <= 0) { Letters = Letters + temp; } } //For each of the for (int l = 0; l < 26; l++) { Count = 0; for (int i = 0; i < Letters.Length; i++) { string sub = Letters.Substring(i, 1); int subz = char.Parse(sub) - 'A'; if(subz == l) { Count++; } } intz[l] = Count; //Outputs the counted letters to listbox lstbxCounted.Items.Add(Convert.ToChar(l + 'A') + "\t" + intz[l]); } } } }
OpenFileDialog
using
StreamReader
Close()
Letters
while
StreamReader.Read()
.Peek()
.Read()
char.ToUpper()
currentLetter - 'A'
int
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)