Last active
November 2, 2017 20:08
-
-
Save teamday/c29d72e964264ea8654f4a713ebc66c5 to your computer and use it in GitHub Desktop.
Trim last wrod regexp "Blah Blah Blah Bl..." -> "Blah Blah Blah..."
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
using System.Text.RegularExpressions; | |
public static class TrimLastWord{ | |
private static Regex _trimLastWord = new Regex(@"\s+?(\S+)?$"); | |
private static string TrimLastWord(this string str, int maxLength, string extra="...") | |
{ | |
if (str?.Length > maxLength) | |
return $"{_trimLastWord.Replace(str.Substring(0, maxLength), "")}{extra}"; | |
return str; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment