How can I divide a sentence like "He and his brother, are playing football."
into few part like "He"
, "He and"
, "and his"
, "his brother"
, "brother, "
,", are"
, "brother playing"
, "playing football"
, "football."
and "."
. Is it possible to do that by using Java?
String[] words = "He and his brother , are playing football .".split("\\s+");
System.out.println(words[0]);
for (int i = 0, l = words.length; i + 1 < l; i++){
System.out.println(words[i] + " " + words[i + 1]);
}
String s = words[words.length-1];
System.out.println(s.charAt(s.length() - 1));
This is the code I have done problem is "," inside the sentence must be separate with the word like "brother,"
must put as this "brother ,"
only will work. Any solution?