vb.net extract first sentence in paragraph

D

dmalhotr2001

Hi,

For string extraction function in vb, if I feed in a paragraph, how do
I extract the first sentence of that paragraph.

Thanks

:D
 
J

Juan T. Llibre

re:
!> For string extraction function in vb, if I feed in a paragraph, how do
!> I extract the first sentence of that paragraph.

Dim sr As New IO.StreamReader("drive:\directory\somefile.txt")
sr.ReadLine()
 
J

Juan T. Llibre

re:
!> Will that work if the first sentence is more than one line long?
!> Or if the first sentence is only a few words long?

That should read until the first line-break is found.
Some care will need to be taken when writing that first line. <g>

There's additional caveats, like if the punctuation includes a semi-colon.

Everything before the semi-colon will be interpreted as a line
and everything past the semi-colon ( and until the line-break)
will be interpreted as a second line.

re:
!> Don't you need to do some sort of regular expression where you find the
!> first instance of a full stop followed by a space and a capital letter...?

Finding the first period and reading everything that came before it would turn the trick, too.
There's also caveats with that method.

See my sig for an example : "Juan T. Llibre, asp.net MVP"

That line has a period followed by a space and a capital letter...but the line doesn't end there.

Bottom line: the problem is a tough nut to crack because of the infinite possibilities in text.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,477
Members
44,898
Latest member
BlairH7607

Latest Threads

Top