mikemind mikemind - 10 months ago 54
C# Question

Unable to remove certain characters between values in c#

I am trying to remove characters starting from (and including)

up to (and including)

Example input string:

Sum ({rgmdaerudsb;1.Total_Value}, {rgmdaerub;1.Major_Value})


string strEx = "Sum ({rgmdaerudsb;1.Total_Value}, {rgmdaerub;1.Major_Value})";
strEx = strEx.Substring(0, strEx.LastIndexOf("rgm")) +
strEx.Substring(strEx.LastIndexOf(";1.") + 3);


Sum ({rgmdaerub;1.Total_Value}, {.Major_Value})

Expected result:

Sum ({Total_Value}, {Major_Value})

Note: only
rgm and ;1.
will remain static and characters between them will vary.

Answer Source

Try this:

string input = "Sum ({rgmdaerudsb;1.Total_Value}, {rgmdaerub;1.Major_Value})";
string result = Regex.Replace(input, @"rgm.*?;1\.", "");