I need this all the time and am constantly frustrated that the Trim(), TrimStart() and TrimEnd() functions don\'t take strings as inputs. You call EndsWith() on a string, an
I like my TrimEnd to remove all the instances of the string at the end and not just the last one.
public static string TrimEnd(this string str, string trimStr)
{
if (string.IsNullOrEmpty(str) || string.IsNullOrEmpty(trimStr)) return str;
while(str.EndsWith(trimStr))
{
str = str.Remove(str.LastIndexOf(trimStr));
}
return str;
}