Imports System
Imports System.Text.RegularExpressions
Module Program
''' <summary>
''' Remove all parentheses and the text inside them.
'''
''' @param text The input string
''' @return The cleaned string
''' </summary>
Function RemoveParenthesesWithContent(text As String) As String
' Remove parentheses and everything inside them
Dim cleaned As String = Regex.Replace(text, "\([^)]*\)", " ")
' Collapse multiple spaces into one
Dim collapsed As String = String.Join(" ", cleaned.Trim().Split({" "c, Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries))
' Final trim of leading/trailing spaces
Return collapsed.Trim()
End Function
Sub Main()
Dim str As String = "(An) API (API) (is a) (connection) connects (between) computer programs"
Dim output As String = RemoveParenthesesWithContent(str)
Console.WriteLine(output)
End Sub
End Module
'
' run:
'
' API connects computer programs
'