// 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 readonly Regex re = new Regex(@"(\w{6})-?(\w{2})-?(\w{2})", RegexOptions.Compiled); public static string Format(string s) { return re.Replace(s, "$1-$2-$3"); } public static void Test(string s) { Console.WriteLine(s + " -> " + Format(s)); } public static void Main(string[] args) { Test("XXXXXX-XX-XX"); Test("XXXXXXXX-XX"); Test("XXXXXX-XXXX"); Test("XXXXXXXXXX"); } } }