Argentini.Halide.H3Text.ReplaceLast C# (CSharp) Méthode

ReplaceLast() public static méthode

Replaces the last occurrence of a string with the replacement value. The replace is case senstive.
public static ReplaceLast ( string input, string oldValue, string newValue ) : String
input string The string to examine.
oldValue string The value to replace.
newValue string the new value to be inserted.
Résultat String
        public static String ReplaceLast(string input, string oldValue, string newValue)
        {
            int index = input.LastIndexOf(oldValue);

            if (index < 0)
            {
                return input;
            }
            else
            {
                StringBuilder sb = new StringBuilder(input.Length - oldValue.Length + newValue.Length);
                sb.Append(input.Substring(0, index));
                sb.Append(newValue);
                sb.Append(input.Substring(index + oldValue.Length, input.Length - index - oldValue.Length));
                return sb.ToString();
            }
        }