Replace string in brackets in VB.NET
I have string with brackets:
Dim A as String = "Example (example1)"
I want to replace string in brackets with another string so I should get for example...
A = "Example (example2)"
You can use the Regex.Replace Method
Imports System.Text.RegularExpressions Dim input As String = "Example (example1)" Dim replacement As String = "example2" Dim expression As New Regex(\(.*\)) Dim result As String = expression.Replace(input, replacement)
That pattern will match anything in-between two parenthesis including other parenthesis (greedy). Adjust expression to suit your need.