Solution1 is best but, if you just want to use your approach, something like this may work.
private static void ReplaceBetween()
{
string replacedText = " some replaced text ";
string[] fileLines = new[] {
"Start text1..blah...blah..123...text2 hello",
"something text1always carry an umbrellatext2 end",
"nothing to be replaced here",
"finally text1Mary had a little lambtext2 finish"
};
string markS = "text1";
string markE = "text2";
for (int i = 0; i < fileLines.Length; i++)
{
string line = fileLines[i];
int start = line.IndexOf(markS);
int end = line.LastIndexOf(markE);
if (start >= 0 && end >= 0)
{
int length = line.IndexOf(markE) + markE.Length - start;
var textToReplace = line.Substring(start, length);
string replacement = markS + replacedText + markE;
var result = line.Replace(textToReplace, replacement);
fileLines[i] = result;
}
}
}