java - Capitalize first word of a sentence in a string with multiple sentences -


eg:

string s="this a.line .over "

should come out

"this a.line is.over"

i thought of using string tokenizer twice

-first split using"."   -second split using " " first word   -then change charat[0].toupper 

now i'm not sure how use output of string tokenizer input another?

also can using split method generate array tried

     string a="this is.a boy";      string [] dot=a.split("\\.");         while(i<dot.length)      {          string [] sp=dot[i].split(" ");             sp[0].charat(0).touppercase();// part? 

use stringbuilder, no need split , create other strings, , on, see code

public static void main(string... args) {  string text = "this a.line is. over";  int pos = 0; boolean capitalize = true; stringbuilder sb = new stringbuilder(text); while (pos < sb.length()) {     if (sb.charat(pos) == '.') {         capitalize = true;     } else if (capitalize && !character.iswhitespace(sb.charat(pos))) {         sb.setcharat(pos, character.touppercase(sb.charat(pos)));         capitalize = false;     }     pos++; } system.out.println(sb.tostring()); } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -