Last active
October 21, 2015 17:49
-
-
Save thiagoaag/d258c3f5dd352c3f7ccc to your computer and use it in GitHub Desktop.
Truncate a long string
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
public static string TruncateAtWord(this string input, int length) | |
{ | |
if (input == null || input.Length < length) | |
return input; | |
int iNextSpace = input.LastIndexOf(" ", length); | |
return string.Format("{0}...", input.Substring(0, (iNextSpace > 0) ? iNextSpace : length).Trim()); | |
} | |
http://stackoverflow.com/a/1614090 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment