I want to split a String into lines with a maximum number of characters per line, while splitting only on whitespace.
example :
if my String is good morning , today is monday good morning , today is monday
number of characters : 11
the output should be
good
morning ,
today is
monday good
morning ,
today is
monday
this is my code for two rows
public String skipRowLettreNumbre(String lettre) {
String ret = lettre + "\n";
if (lettre.length() > 36) {
String after50 = lettre.substring(36);
for (int i = 0; i < after50.length(); i++) {
if (after50.substring(i, i + 1).equals(" ")) {
String part1 = lettre.substring(0, i + 36);
String part2 = lettre.substring(i + 36, lettre.length());
ret = part1 + "\n " + part2;
break;
}
}
}
return ret + "";
}