T.Malo T.Malo - 1 month ago 8
Vb.net Question

VB sentence count

I am trying to write a program that will count the number of sentences in a string. I would like to better use the framework has much has possible but I really don't understand this msdn example. So could someone explain it if they understand or does someone know how to count the number of sentences in a sting accurately? I am open to all and any suggestions.

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.sentences.count.ASPX?cs-save-lang=1&cs-lang=vb#code-snippet-1

EDIT:

Ok, for anyone that has had a hard time with counting sentences (like me) here is what I have been able to come up with and I think this is has good as you can get it. So if anyone else has a idea on how to solve sentences counting let me know. But what I have and it works.

My idea is that a sentences is defined has ". or ! or ?" and followed by at least one space. So this what seems to work. (Sorry its not a fully working module because I copied it out of class I'm using).

'Period cehck
For i As Integer = 0 To _runFor
If (str(i) = _Dot And True = Char.IsWhiteSpace(str(i + 1))) Then
_sentence_count = _sentence_count + 1
End If
Next

'Question check
For i As Integer = 0 To _runFor
If (str(i) = _Question And True = Char.IsWhiteSpace(str(i + 1))) Then
_sentence_count = _sentence_count + 1
End If
Next


'Exclamation check
For i As Integer = 0 To _runFor
If (str(i) = _Exclamation And True = Char.IsWhiteSpace(str(i + 1))) Then
_sentence_count = _sentence_count + 1
End If
Next

Answer

It's not really possible to accurately count sentences programmatically. For instance, if you wrote a piece of code that just counted the number of occurrences of a period followed by a space followed by a capital letter, then it would incorrectly interpret "I gave my report to Dr. Johnson." as two sentences.