' 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.IO
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
            Using sr As New StreamReader("input.html")
                input = sr.ReadToEnd()
            End Using
            Dim replacements As New Dictionary(Of String, String)()
            Using sr As New StreamReader("repl.properties")
                Dim line As String
                line = sr.ReadLine()
                While line IsNot Nothing
                    Dim parts As String() = line.Split("="C)
                    replacements.Add(parts(0).Trim(), parts(1).Trim())
                    line = sr.ReadLine()
                End While
            End Using
            Dim output As String = Replace(input, replacements)
            Console.WriteLine(output)
        End Sub
    End Class
End Namespace
