Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Truncates the string.
- /// </summary>
- /// <param name="txt">String to truncate.</param>
- /// <param name="maxChars">Maximum string length.</param>
- /// <returns>String truncated to length.</returns>
- public static string Truncate(string txt, int maxChars)
- {
- if(string.IsNullOrEmpty(txt) )
- return txt;
- if(txt.Length <= maxChars)
- return txt;
- return txt.Substring(0, maxChars);
- }
Advertisement
Add Comment
Please, Sign In to add comment