Re: Help ArrayLis won't store, and how to remove duplicates????
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 08/24/04
- Next message: Thomas: "Re: Input null into a DateTime property."
- Previous message: Ken Arway: "Re: Selecting current row in DataGrid after sorting"
- Maybe in reply to: Bob Grommes: "Re: Help ArrayLis won't store, and how to remove duplicates????"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 24 Aug 2004 03:09:01 +0100
steve smith <boy_wonder48@hotmail.com> wrote:
> Hi many thanks for all the replies, however i am still getting some
> problems My sort seems to be roking fine, as they come out as they
> should, however in my output file it seems as my contains check does
> not seem to work as i am getting the same wor repeating many times.
> Also a word cound in word reveals there are 2218 words, however
> program says there are 2789 words. Ihave since changed the program, to
> capitalise the first letter of each word and to also put a count of
> the number of occurences of each word, the code and sample of output
> file posted below, any help with this is much appreciated. Thanks.
The problem is that you're seeing whether the non-proper-cased word is
in the ArrayList, then proper-casing it and adding it. So, for
instance, you never add "a" to the ArrayList, only "A" - so every time
"a" comes up, it will check whether that's in the list, never find it,
and add it.
If you change the middle bit of your code to:
string proper = ToProperCase(mySplit[x]);
if (!myList.Contains(proper))
{
myList.Add(proper);
}
then you'll only get each word once.
(Of course, you then need to change to a different way of determining
how many occurrences there are.)
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Thomas: "Re: Input null into a DateTime property."
- Previous message: Ken Arway: "Re: Selecting current row in DataGrid after sorting"
- Maybe in reply to: Bob Grommes: "Re: Help ArrayLis won't store, and how to remove duplicates????"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|