RemoveRightIfPresent
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"));