Hi
I am trying a program which takes the input from the user, the program will convert all the multiple blank spaces into a single blank space. It will also create a new line after a sentence is declared. my logic is to find where is "! . or ?" in the string, if it founds one then the sentence is declared. I want to capitalize the first word of the sentence. This is my code please check it out.
Code:
public String parsentence(String sent) {
String t1;
for (int x = 0; x <= sent.length(); x ++) {
if ((sent.indexOf(sent.charAt(x)) + 1) != sent.length()){
if ((sent.charAt(x) & sent.charAt(x + 1)) == ' ') {
t1 = sent.charAt(x + 1) + "";
sent = sent.replaceFirst(t1, "");
}
if (((sent.charAt(x) == '.') || (sent.charAt(x) == '!') || (sent.charAt(x) == '?')) & (sent.charAt(x + 1) == ' ')) {
t1 = sent.charAt(x + 1) + "";
sent = sent.replaceFirst(t1, "\n");
sent = sent.replace(sent.charAt(x + 2), Character.toUpperCase(sent.charAt(x + 2)));
}
}
}
return sent;
}
Any advice or suggestion on this.
Bookmarks