I want to replace a section of text in a file the section should start with //BEGIN: and end with //END:
the replacement is just a black line,
this is the code i use:
text = Regex.Replace(text, @"//(.*?)\r?\n", me =>
{
bool x = false;
if (me.Value.StartsWith("//BEGIN:"))
{
x = true;
return me.Value.StartsWith("//BEGIN:") ? Environment.NewLine : "";
}
if (x == true)
{
return Environment.NewLine;
}
if (me.Value.StartsWith("//END:"))
{
x = false;
return me.Value.StartsWith("//END:") ? Environment.NewLine : "";
}
return me.Value;
}, RegexOptions.Singleline);
but it isn't working like i want to.