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. |
return | 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();
}
}