mikemind mikemind - 15 days ago 4
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
;1
only

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


Expected Result:

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

Answer

A simple solution would be:

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