27
1
using System;
2
3
public class Program
4
{
5
public string GetInnermostString(string input, string startDelimiter, string endDelimiter)
6
{
7
int startIndex = input.LastIndexOf(startDelimiter) + startDelimiter.Length;
8
int endIndex = input.IndexOf(endDelimiter, startIndex);
9
10
if (startIndex >= 0 && endIndex >= 0 && startIndex <= endIndex)
11
{
12
return input.Substring(startIndex, endIndex - startIndex);
13
}
14
return string.Empty; // or throw an exception if not found
15
}
16
17
public void Main()
18
{
19
20
// Example usage:
21
//string text = "a(b(c)d)e"; // result will be "c", verified!
22
//string text = "a(b(c)d)e)"; // test1
23
string text = "(a(b(c)d)e"; // test2
24
Console.WriteLine( GetInnermostString(text, "(", ")") ); // result will be "c"
25
26
}
27
}
Cached Result
c