Original Post
Hello, I am constructing a program to read text from a webpage, filter out the html tags and common words ("the", "as", "and", etc.) and output the filtered text to a text file. I'm having trouble filtering out the common words, however. I think it's just the basic string comparison. Here is the function:
String* filter_cw(String* text_string)
{
StreamReader* infile = new StreamReader("common.txt");
ArrayList* cw_list = new ArrayList();
String* word = "";
//Store all common words into array cw_list
word = infile->ReadLine();
while(word!=0)
{
cw_list->Add(word);
word = infile->ReadLine();
}
infile->Close();
Char chars[] = {' ', ',', '.', ':', '-', '\n'};
String* word_array[] = text_string->Split(chars);
IEnumerator* listEnum = word_array->GetEnumerator();
//StringBuilder filtered_text; not in use yet
bool isCommon;
while(listEnum->MoveNext())
{
isCommon = false;
String* s = listEnum->current->ToString();
for(int i=0;i<cw_list->Count;i++)
{
String* cw = cw_list->Item->ToString();
if(String::Compare(s,cw,true)==0) //DOES NOT WORK
{
Console::WriteLine(s);
break;
}
}
}
return "random string";
}
There are no compiler errors, everything seems to work except the comparison. So, this function takes in a string of text - it reads the list of common words from a file and stores them in an array. Then it splits the string that was passed to it into an array of strings divided at punctuation marks and whitespaces. It then should compare each word from the string to each common word, however, no string comparison i use works, i've tried String::Compare, String::Equals, ==, and at one point made my own string comparison function that compared character by character, nothing worked. It just says that none of the words match. I'm very new to .NET, been working on this for a while and can't figure it out, any help would be very much appreciated. Thanks.