Posted By


stuartleitch on 06/10/11

Tagged


Statistics


Viewed 438 times
Favorited by 1 user(s)

StringTruncator


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. namespace System
  2. {
  3. public static class StringTruncator
  4. {
  5. /// <summary>
  6. /// Trims and truncates to specified length if required.
  7. /// </summary>
  8. public static string Truncate(this string item, int length)
  9. {
  10. return item.Trim().Substring(0, Math.Min(item.Trim().Length, length));
  11. }
  12. }
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.