Results 1 to 6 of 6

Thread: paragraph and sentence count

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    33

    paragraph and sentence count

    how would I count the number of paragraphs and sentences of a text file in a text box?

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    What do you mean by a sentence?! If you mean anything that is ended by a '.' , '!' or '?' and combinations like "?!!!" is a sentence then you might apply a method to count them and thats easy. And for paragraphs, again you have to define it. if you define a paragraph where "Enter' is pressed and you go to another line you may get the line numbers of the text file, that is ReadLine of streamreader till you are at the end of file, or count the number of Linefeed/Carriage Return characters.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    33

    sentence and paragraph

    I want to count sentences ending with a period, question mark, or exclamation mark. And for paragraphs I guess I would count every enter or double enter as a paragraph. Im not really sure how to count the paragraphs. I dont know what the code should look like.

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    You may use RegEx to count them.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    33

    regex

    I was going to use the regex method. But my reacher told me it was to high a level of a function. I almost have my paragraph count working the only fault in it is that if i have 3 paragraphs in the textbox it only counts 2 should I automatically add 1 to the paragraph variable at the end or should I add some other line of code here is what I have so far. I am counting 2 carriage returns as a paragraph.

    Dim sr As IO.StreamReader = IO.File.OpenText(filename)
    Dim theline As String
    TextBox2.Clear()
    TextBox2.Multiline = True
    Do While sr.Peek <> -1

    theline = sr.ReadLine
    If theline.Length = 0 Then
    paragraph = paragraph + 1
    End If
    TextBox2.Text = TextBox2.Text + theline + vbCrLf
    Loop
    sr.Close()
    TextBox1.Text = filename
    End Sub

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    33

    forgot

    I forgot to tell you that I am counting the paragraphs as they are put into the textbox with the streamreader.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width