// 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; using System.Text.RegularExpressions; public class HtmlManip { public static void Main(string[] args) { test("bla beskrivelse bla"); test("bla beskrivelse1blabeskrivelse2bla"); } private static void test(string s) { Console.WriteLine(s); Console.WriteLine(LinkReplace(s)); } public static string LinkReplace(string s) { MatchCollection res = Regex.Matches(s,"(.*?)()(.*?)()(.*)"); StringBuilder sb = new StringBuilder(""); for(int i = 0; i < res.Count; i++) { sb.Append(res[i].Groups[1]); sb.Append("#(a href=\""); sb.Append(res[i].Groups[3]); sb.Append("\"#)"); sb.Append(res[i].Groups[5]); sb.Append("#(/a#)"); sb.Append(res[i].Groups[7]); } return sb.ToString(); } }