468,103 Members | 1,332 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

Processing a Textfile

Hi

Using C# and a textfile I need to do two things:

1. Read the contents of the textfile and return the number of words
contained in it.
2. Output a list of unqiue words (i.e. not duplicated) to a new textfile.
These words should appear on a new line.
eg.
hello
world

This needs to be done in C# and I am struggling to understand how to do this
using the TextReader and TextWriter.

Any help greatly appreciated.

Thanks

Kevin
Nov 16 '05 #1
4 1363
Use the StreamReader class, you can then use the Split() method in
string to split words and store them in a hashtable (or whatever data
structure you have that preserves uniqueness). You can then write it
the hashtable out to a file.

Nov 16 '05 #2
Thanks for that. Could you provide a coded example as it is not something I
have used before?

Thanks

Kevin

"sadhu" wrote:
Use the StreamReader class, you can then use the Split() method in
string to split words and store them in a hashtable (or whatever data
structure you have that preserves uniqueness). You can then write it
the hashtable out to a file.

Nov 16 '05 #3
<"=?Utf-8?B?S2V2aW4gSm9obnNvbg==?=" <Kevin
Jo*****@discussions.microsoft.com>> wrote:
Thanks for that. Could you provide a coded example as it is not something I
have used before?


Which part of it? I'd suggest trying it yourself first, then posting
your attempt, and what you're having trouble with - that way you'll
learn a lot more than if someone just gives you all the code you need
to start with.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
So have u been able to do it?

Ab.
"Kevin Johnson" <Kevin Jo*****@discussions.microsoft.com> wrote in message
news:4A**********************************@microsof t.com...
Thanks for that. Could you provide a coded example as it is not something I have used before?

Thanks

Kevin

"sadhu" wrote:
Use the StreamReader class, you can then use the Split() method in
string to split words and store them in a hashtable (or whatever data
structure you have that preserves uniqueness). You can then write it
the hashtable out to a file.

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.