Skip to content

Instantly share code, notes, and snippets.

@massimilianochiodi
Created April 15, 2022 08:39
Show Gist options
  • Save massimilianochiodi/70a4a32ba1326430f708766fbaa179cd to your computer and use it in GitHub Desktop.
Save massimilianochiodi/70a4a32ba1326430f708766fbaa179cd to your computer and use it in GitHub Desktop.
Word Wrap Text ( java ) add /n to text at specific size
private String wordwrap(String testo, int dimensione ) {
String temp_testo;
temp_testo = Html.fromHtml(testo, Html.FROM_HTML_MODE_LEGACY).toString();
StringBuilder sb = new StringBuilder(temp_testo);
int i = 0;
while (i + dimensione < sb.length() && (i = sb.lastIndexOf(" ", i + dimensione)) != -1) {
sb.replace(i, i + 1, "\n");
}
return sb.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment