Posted By

stuartleitch on 06/10/11


Tagged

truncate c#


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ovuncgursoy


StringTruncator


 / Published in: C#
 

  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  

You need to login to post a comment.