mikemind mikemind - 1 year ago 107
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";

Answer Source

A simple solution would be:

strValue = strValue.Substring(0, strValue.LastIndexOf("rgm")) + strValue.Substring(strValue.LastIndexOf(";1") + 2);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download