28
1
using System;
2
3
public class Program
4
{
5
public static void Main()
6
{
7
string input = "Outer[Middle[Innermost]Middle]Outer";
8
string start = "[";
9
string end = "]";
10
11
string result = GetInnermostString(input, start, end);
12
Console.WriteLine("Innermost string: " + result);
13
}
14
15
public static string GetInnermostString(string input, string start, string end)
16
{
17
int endIndex = input.LastIndexOf(end);
18
if (endIndex == -1) return ""; // End marker not found
19
20
int startIndex = input.LastIndexOf(start, endIndex - 1);
21
if (startIndex == -1) return ""; // Start marker not found
22
23
startIndex += start.Length;
24
25
return input.Substring(startIndex, endIndex - startIndex);
26
}
27
}
28
Cached Result