Q:

Check whether 3 strings are located in a same sentence or not -Java

I am checking whether 3 strings located in a same sentence or not.
For example the sentence  Barack born on November 4 1960.
In this sentence string1 is Barack Obama
                string2 is born on
                string3 is November 4 1960
MY idea is to check if there is no period(".") in between string1, string2, and string3, I can believe that 3 strings located in a same sentence.
But sometimes the sentence is like Mr.smith and mrs.smith both born on April 2 1970.
If i just check for period(".") my approach fails. Can someone suggest me is there any other way to check for 3 strings located in a same sentence or not?

A:

As said in the comments, use BreakIterator. It does the right thing for you.
BreakIterator i=BreakIterator.getSentenceInstance(Locale.US);
final String text = "Mr. smith and mrs.smith both born on April 2 1970. Barack born on November 4 1960.";
i.setText(text);
for(int s=i.first(), e=i.next(); e>=0; s=e, e=i.next())
{
  System.out.println("Sentence: from "+s+" to "+e+" \""+text.substring(s, e)+'"');
}

Once you know the boundaries of the sentences, you should know how to match the found string locations with it.

