Skip to content

Instantly share code, notes, and snippets.

@radiatoryang
Created December 28, 2013 07:42
Show Gist options
  • Save radiatoryang/8157056 to your computer and use it in GitHub Desktop.
Save radiatoryang/8157056 to your computer and use it in GitHub Desktop.
Word Wrapping in Unity C#, based on some Tale of Tales code
// courtesy of Tale of Tales!
string WordWrap(string text, int lineLength) {
for (int i = lineLength; i < text.Length; i += lineLength) {
int returnSpot = text.LastIndexOf(" ", i);
if (returnSpot >= 0){
text = text.Substring(0, returnSpot) + "\n" + text.Substring(returnSpot, text.Length-returnSpot);
i = returnSpot;
}
}
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment