Re: Help ArrayLis won't store, and how to remove duplicates????

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 08/24/04


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


Relevant Pages

  • Re: sort(1)
    ... an output file, sorting by the first 3 characters on a line eg 1.2, in ... 4DOS and not using some other util like sort or gsar. ... an entire file into memory it will take too much memory and even then ... it cannot do everything and could never beat the good old Unix text processing tools. ...
    (comp.os.msdos.4dos)
  • Re: Efficiency Question: Large Arrays vs. Indexed Files on Alphas
    ... >decide to read some fields of some records into an array and ... >maintain records that will eventually be written to an output file ... saved the entire file contents in dynamic memory and the SOR$ utility ... routines to sort them, then formatted the records for the output file. ...
    (comp.os.vms)
  • Re: Trying to understand sort and anonymous sub
    ... > $daynum" loop in the code shown below. ... I know it's an anonymous sub, ... > resultant output file contains the following: ... The first sort is using the specified subroutine to sort ...
    (perl.beginners)
  • Re: Need to sort a very large list of words
    ... Then pull out using ORDER BY clause and ... write to output file. ... I figure I'll write a program to sort the file. ...
    (microsoft.public.dotnet.languages.csharp)