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

Description

Removes end of string if it equals to parameter, otherwise returns origin string

Details

  • Author: Dmitry
  • Submitted on: 5/17/2013 7:22:07 AM
  • Language: C#
  • Type: string
  • Views: 1750

Double click on the code to select all.

 

;