Well,
Here is what I need to do:
I need to split the text from a .txt file into a list of the words in the file (which I have done) I then need to count each word and list them so that there are no repeating words in the list ( each word appears only one with a number next to it representing how many times it occurs). I am assuming I can use a hashtable for this but don't know where to begin.
The next thing I need to do is, perform an http request and find the top 5 google searched for the 3 words that appear the most and display the results.
Here is what i have so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
namespace ConsoleApplication2
{
class SplitTextFile
{
static void Main(string[] args)
{
FileStream file = new FileStream("input.txt", FileMode.OpenOrCreate, FileAccess.Read);
StreamReader sr = new StreamReader(file);
string s = sr.ReadToEnd();
sr.Close();
file.Close();
char[] delim = { ' ', '\t', '\r', '\n' };
string[] words = s.Split(delim);
foreach (string word in words)
{
Console.WriteLine(word);
}
Console.ReadLine();
}
}
}
Loading
Adam RaybornPosted Dec 9, 2008, 12:41 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
namespace ConsoleApplication2
{
class SplitTextFile
{
static void Main(string[] args)
{
FileStream file = new FileStream("input.txt", FileMode.OpenOrCreate, FileAccess.Read);
StreamReader sr = new StreamReader(file);
string s = sr.ReadToEnd();
sr.Close();
file.Close();
char[] delim = { ' ', '\t', '\r', '\n' };
wordFreq = new Hashtable();
string[] words = s.Split(delim);
foreach (string word in words)
{
if (words[i] != "")
{
bool realWord = true;
for (int j = 0; j < words[i].Length; j++)
{
if (char.IsLetter(words[i][j]) == false)
{
realWord = false;
}
}
if (realWord == true)
{
if (wordFreq.Contains(words[i].ToLower()))
{
wordFreq(words[i].ToLower()) += 1;
}
else
{
wordFreq.Add(words[i].ToLower(), 1);
}
}
}
}
this.wordCount = new SortedList();
foreach (DictionaryEntry de in wordFreq)
{
if (wordCount.ContainsKey(de.Value) == false)
{
wordCount.Add(de.Value, de.Key);
}
}
}
}
}