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)"

Answers


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.


Need Your Help

why are the File.hashCode() different

android sharedpreferences hashcode

This is the code that I use to copy sharedpreference file toand fro from sdcard.

Vodafone Mobile Broadband K3765-Z not working in jessie but was working in wheezy

networking usb debian wireless umts

I was working on Debian stable=wheezy until last week. Using my Surfstick was fine - configured by network-Manager.