' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
﻿Imports System
Imports System.Collections.Generic
Imports System.Text.RegularExpressions

Namespace E
    Public Class Program
        Public Shared Function Replace(input As String, replacements As Dictionary(Of String, String)) As String
            Dim res As String = input
            Dim re As New Regex("{(\w+)}")
            For Each m As Match In re.Matches(input)
                Dim id As String = m.Groups(1).Value
                res = res.Replace("{" & id & "}", If(replacements.ContainsKey(id), replacements(id), ""))
            Next
            Return res
        End Function
        Public Shared Sub Main(args As String())
            Dim input As String = "A: {A} B: {B} C: {C} D: {D}"
            Dim replacements As New Dictionary(Of String, String)()
            replacements.Add("A", "This is A")
            replacements.Add("C", "This is C")
            Dim output As String = Replace(input, replacements)
            Console.WriteLine(input)
            Console.WriteLine(output)
        End Sub
    End Class
End Namespace
