For a common problem, I would suggest using Regex
. However, if you are confident in the format of the input string (only one set of partners, open your finger in front of a close pair), this will work:
int startIndex = s.IndexOf('(') + 1; string result = s.Substring(startIndex, s.LastIndexOf(')') - startIndex);
source share