hi

i would go for processing the string format. So make the reader read all the
content into a string and then manipulate the string. I'm sorry but my
example is in VB. Had an active window and was to lazy to convert it, or
open a new one.

'// Read the FileContent into a string
Dim fs As New System.IO.FileStream("c:\sometextfile.txt", IO.FileMode.Open)
Dim sr As New System.IO.StreamReader(fs)
Dim ContentString As String = sr.ReadToEnd

'// To Get the Number of Lines:
Dim LineNum As Integer = ContentString.Length

'// To get the number of Words:
Dim ArrWords() As String = ContentString.Split(Chr(32))
Dim WordNum As Integer = ArrWords.Length

fs = Nothing
sr = Nothing
ContentString = Nothing

As you can see i left out the sentences. The main reason for that is because
sentences are kind of hard to pick out. A sentence can end with
!,?,.,?!?,etc
so in order to get a count of that you should write a recursive function to
scan the text.

hope this helps. If you need help with the conversion, give a call

regards

remie bolte




----- Original Message -----
From: "Tiffany Blake" <[EMAIL PROTECTED]>
To: "ActiveServerPages" <[EMAIL PROTECTED]>
Sent: Thursday, October 31, 2002 3:58 PM
Subject: RE: .Net text file stream


answer:
1) cs0103: the name 'line' does not exist in class/namespace AND cs1501: no
overload method for 'read' takes '2' arguments
2) it doesn't matter if spaces are counted
3) the text file i'm referencing is 1KB

reply to comments:
- my code includes a StreamReader to read the entire text file into a string
FileStream inStream = new FileStream("filestream.txt",FileMode.Open);
StreamReader reader = new StreamReader(inStream);

//initialize counter for file data rows
int linenum = 1;

//read file and write contents to console
for (string line = reader.ReadLine(); line != null;line
= reader.ReadLine(), linenum++)
- i received compile errors when i tried to invoke the String.Length
function

thanks again for your help!!

-----Original Message-----
From: Matthew Small [mailto:matt6@;showstopperonline.com]
Sent: Thursday, October 31, 2002 6:39 AM
To: ActiveServerPages
Subject: RE: .Net text file stream


OK, questions:
1) What is the error that you are getting?
2) Are spaces considered characters?
3) What is the longest text file that will be read?

Next, comments:
If it's a relatively short text file (I think anything under a million
characters is reasonable [1 Mb?], anybody else is welcome to chime in
here on this) then I would read the entire text file into one string and
then parse it. The way I would parse it is this:

1) Characters are easily counted if spaces are counted as well.
String.length().  If spaces are not counted, then either count the
number of spaces in the string and substract it from the length or do a
string.replace() on the string until all of the spaces have been
eliminated.  Don't do this until the end so you don't mess up the words.

2) I think that you can consider words to be anything that is between a
space.  Therefore, the number of words you have is (number of spaces -
1).

3) Sentences should be equal to the number of periods, question marks,
and exclaimation points as long as they each have a space after it.
Examples:

"You're doing what???" = 1 sentence because of the space after the last
question mark

"I want to go to the fair (the one where Sally won't be there!) and eat
popcorn." = 1 sentence because the exclaimation point does not have a
space after it.

"I think that object.method will work." = 1 sentence


Hope it helps.

Matthew Small
IT Supervisor
Showstopper National Dance Competitions
3660 Old Kings Hwy
Murrells Inlet, SC 29576
843-357-1847
http://www.showstopperonline.com

-----Original Message-----
From: Tiffany Blake [mailto:Tiffany_Blake@;gap.com]
Sent: Thursday, October 31, 2002 9:28 AM
To: ActiveServerPages
Subject: RE: .Net text file stream

Matthew - thanks for responding...

my problem is the code won't compile and i can't figure out how to count
chars, words and sentences.  i really am a newbie...

[EMAIL PROTECTED]
-----Original Message-----
From: Matthew Small [mailto:matt6@;showstopperonline.com]
Sent: Thursday, October 31, 2002 6:20 AM
To: ActiveServerPages
Subject: RE: .Net text file stream


So what exactly is the problem?  Is it that you can't figure out how to
count sentences, that it doesn't compile, both, or something else?


Matthew Small
IT Supervisor
Showstopper National Dance Competitions
3660 Old Kings Hwy
Murrells Inlet, SC 29576
843-357-1847
http://www.showstopperonline.com

-----Original Message-----
From: Tiffany Blake [mailto:Tiffany_Blake@;gap.com]
Sent: Thursday, October 31, 2002 8:58 AM
To: ActiveServerPages
Subject: .Net text file stream
Importance: High

sorry - i'm a .net newbie so here goes...

- i'm using a text file stream for input
- my goal is to output the # of characters, words and sentences
- instead of counting # of sentences i counted the # of lines in
the file
- i have partial solution for characters and words

any ideas?  here's my code
........
using System;
using System.IO;
using System.Text;

class Class1
{
//read a text file to perform string manipulation

static void Main(string[] args)
{
//open text file
FileStream inStream = new FileStream("filestream.txt",
FileMode.Open);
StreamReader reader = new StreamReader(inStream);

//initialize counter for file data rows
int linenum = 1;

//read file and write contents to console
for (string line = reader.ReadLine(); line != null;line
= reader.ReadLine(), linenum++)
Console.WriteLine(line);
Console.WriteLine(linenum);

// create array to hold all the characters file contents
string(line),
char[] tbArray = new char[50];

//read string(line)  ** HELP ** this is where compile
bombs
StringReader strReader = new StringReader(line);
strReader.Read(tbArray, 0);

   // Display the output.
   Console.WriteLine(tbArray);






//close file
reader.Close();
strReader.Close();
}
}
........
thanks and truly greatful (i've been up all nite!)
[EMAIL PROTECTED]

---
You are currently subscribed to activeserverpages as:
[EMAIL PROTECTED]
To unsubscribe send a blank email to
%%email.unsub%%




---
You are currently subscribed to activeserverpages as:
[EMAIL PROTECTED]
To unsubscribe send a blank email to %%email.unsub%%

---
You are currently subscribed to activeserverpages as:
[EMAIL PROTECTED]
To unsubscribe send a blank email to
%%email.unsub%%




---
You are currently subscribed to activeserverpages as: [EMAIL PROTECTED]
To unsubscribe send a blank email to %%email.unsub%%

---
You are currently subscribed to activeserverpages as: [EMAIL PROTECTED]
To unsubscribe send a blank email to
%%email.unsub%%



---
You are currently subscribed to activeserverpages as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Reply via email to