473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1523
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Hans A | last post by:
I have a textfile "textfile.txt" containing a list of words. There is one word on each line. I want to pick two random lines from this textfile, and I have tried to do something like: //Loading...
6
by: Anders Søndergaard | last post by:
Hi, I'm trying to process a large filesystem (+20 million files) and keep the directories along with summarized information about the files (sizes, modification times, newest file and the like)...
1
by: kachokaratz | last post by:
well i have a problem in my project..since the contents of my textfile is too long, i was wondering how to output the textfile in such a way that you can divide the contents to be able to output...
1
by: asedt | last post by:
With my Excel macro and two text files I want to create a new textfile containing the first textfile then text from the sheet and then the second textfile. My problem is that i don't know how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.