RemoveRightIfPresent
Removes end of string if it equals to parameter, otherwise returns origin string
Source
public static string RemoveRightIfPresent(this string s, string remove, bool ignoreCase = false)
{
int rlen = remove.Length;
if (s.EndsWith(remove, ignoreCase, System.Globalization.CultureInfo.CurrentCulture))
{
return s.Substring(0, s.Length - rlen);
}
else
{
return s;
}
}
Example
string stoTest = "abc@mail.ru";
string res = "abc";
Assert.AreEqual(res,stoTest.RemoveRightIfPresent("@mail.ru"));