I am getting a couple of build errors in my code.
The first of which is:
'wordFreq' is a 'variable' but is used like a 'method'
it says that on the line:
wordFreq(words[i].ToLower()) += 1;
I am also getting an error that says:
The name ' i ' does not exist in the current context
Here is my code:
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);
Hashtable wordFreq = new Hashtable();
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);
}
}
}
}
SortedList wordCount = new SortedList();
foreach (DictionaryEntry de in wordFreq)
{
if (wordCount.ContainsKey(de.Value) == false)
{
wordCount.Add(de.Value, de.Key);
}
}
}
}
}
Loading
Bechir BejaouiPosted Dec 12, 2008, 8:58 AM
systaxically the variable is like this form
VariableName
Meanwhile a method is like this
MethodName( some argument here...)
the functionalities are also different
the variables stock values or represent objects but methods leverage instruction, in your case this is a variable it coudn't be ........(some arguments...)
but as an object it could has a method but it coudn't itself be a method like
if you want to add element to a List you do
myList.Add(element) and not myList(element)
Adam RaybornPosted Dec 11, 2008, 9:58 AM
'wordFreq' is a 'variable' but is used like a 'method'
It shows up on line 40:
wordFreq(word.ToLower()) += 1;
Here is all of my code 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);
Hashtable wordFreq = new Hashtable();
foreach (string word in words)
{
if (word != "")
{
bool realWord = true;
for (int j = 0; j < word.Length; j++)
{
if (char.IsLetter(word[j]) == false)
{
realWord = false;
}
}
if (realWord == true)
{
if (wordFreq.Contains(word.ToLower()))
{
wordFreq(word.ToLower()) += 1;
}
else
{
wordFreq.Add(word.ToLower(), 1);
}
}
}
}
SortedList wordCount = new SortedList();
foreach (DictionaryEntry de in wordFreq)
{
if (wordCount.ContainsKey(de.Value) == false)
{
wordCount.Add(de.Value, de.Key);
}
}
}
}
}
Bechir BejaouiPosted Dec 10, 2008, 9:56 AM
int i = 0;
you have to use and integer as a word counter becasue a the freqword is a hash table it couldn't be a counter only integer could play the role of a counter