Created
April 15, 2022 08:39
-
-
Save massimilianochiodi/70a4a32ba1326430f708766fbaa179cd to your computer and use it in GitHub Desktop.
Word Wrap Text ( java ) add /n to text at specific size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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