mikemind mikemind - 2 months ago 34
C# Question

Remove characters between in c#

I have a string values like this

string strValue = "!return.ObjectV,rgmK12D;1.Value";

In this string how can I remove characters from
rgm to ;1

Below code will remove all the characters from rgm, but I need to remove upto

strValue = strValue.Substring(0, strValue.LastIndexOf("rgm"));

Expected Result:

string strValue = "!return.ObjectV,.Value";


A simple solution would be:

strValue = strValue.Substring(0, strValue.LastIndexOf("rgm")) + strValue.Substring(strValue.LastIndexOf(";1") + 2);