raj shukla

raj shukla

  • NA
  • 1
  • 1.5k

how to print last word of any without breaking,last word should be print from next line

Oct 22 2012 12:36 PM
string input="Flat No-4324,Near Ganga Institute, Tehsil-Raipur, Distt-Banglore,State-Karnataka Pin-644487 India";
 
in the input string perhaps there are 96 character.
 
i want to make a program by which input.length always divided by 20(input.length/20)
and print,so in this case input will print in 5 line.In first line the last word is -Ganga(here in first line it will print-Flat No-4324,Near Ga)and the remaining again in 2nd line starting with- nga Institute.......(so here is problem)
 
i want that if the last letter length exceeded from length 20 then it should print from 2nd line,as i want then 1st line will be(Flat No-4324,Near ) then 2nd line start with Ganga Institute..... and if again this condition occur then so on .
 

If u r not getting so let's take below explanation--
 
i m saying that if,my every line length will be suppose 11 character,so there are some problem occur to print strings like this->( I want to play football and I want to play chess.)
1st line will take 11 character which will be(I want to p),in 2nd line will print(lay footbal) and so on.So here u can see play divide into 2 words p and lay,again football is dividing in 2 words footbal and l,so this is a problem.I want if this type of situation occur then complete word should be start from next line,as i want then 1st line will be(I want to) then 2nd line will be(play) and in 3rd line (football) and so on.
 
plz help

Answers (1)