using System;
using System.Text.RegularExpressions;
/**
* Remove all parentheses and the text inside them.
*
* @param text The input string
* @return The cleaned string
*/
class Program
{
public static string RemoveParenthesesWithContent(string text) {
// Remove parentheses and everything inside them
string cleaned = Regex.Replace(text, "\\([^)]*\\)", " ");
// Collapse multiple spaces into one
string collapsed = string.Join(" ",
cleaned.Trim().Split((char[])null, StringSplitOptions.RemoveEmptyEntries));
// Final trim of leading/trailing spaces
return collapsed.Trim();
}
static void Main()
{
string str =
"(An) API (API) (is a) (connection) connects (between) computer programs";
string output = RemoveParenthesesWithContent(str);
Console.WriteLine(output);
}
}
/*
run:
API connects computer programs
*/