// 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)
using System;
using System.Text.RegularExpressions;
namespace E
{
public class Program
{
private static string Convert(string s)
{
switch(s)
{
case "dato":
return DateTime.Now.ToString("dd-MM-yyyy");
case "dato-1":
return DateTime.Now.AddDays(-1).ToString("dd-MM-yyyy");
default:
throw new ArgumentOutOfRangeException("Unknown function");
}
}
private static readonly Regex re = new Regex("(?:@@)(.*?)(?:@@)", RegexOptions.Compiled);
public static string Process(string s)
{
string res = s;
foreach(Match m in re.Matches(s))
{
res = res.Replace(m.Groups[0].Value, Convert(m.Groups[1].Value));
}
return res;
}
public static void Main(string[] args)
{
Console.WriteLine(Process(""));
Console.WriteLine(Process(""));
}
}
}