Har oversat til C# og ændret url til link, lavet alle \ om til \\, jeg får en fejl når jeg vil complie om en escape.. Nogen ide om hvorfor?.. Og så vil jeg lige spørge hvorfor funktionerne er Shared/static?..
using System;
using System.Text;
using System.Text.RegularExpressions;
public class Links
{
public static void Main(string[] args)
{
Test("[url]http://www.exp.dk[/url]");
Test("
Tryk Her");
Test("bla [url]http://www.exp.dk[/url] bla
Tryk Her bla");
}
private static void Test(string s)
{
Console.WriteLine(s);
Console.WriteLine(LinkCreate(s));
}
public static string LinkCreate(string s)
{
return LinkCreate2(LinkCreate1(s));
}
public static string LinkCreate1(string s)
{
Match m = Regex.Match(s, "(.*?)(?:\\[link\\])(.*?)(?:\\[/link\\])(.*)", RegexOptions.Singleline);
if (m == Match.Empty) {
return s;
} else {
return m.Groups(1).ToString + "<a href='" + m.Groups(2).ToString + "'>" + m.Groups(2).ToString + "</a>" + LinkCreate(m.Groups(3).ToString);
}
}
public static string LinkCreate2(string s)
{
Match m = Regex.Match(s, "(.*?)(?:\\[link=)(.*?)(?:\\])(.*?)(?:\\[/link\\])(.*)", RegexOptions.Singleline);
if (m == Match.Empty) {
return s;
} else {
return m.Groups(1).ToString + "<a href='" + m.Groups(2).ToString + "'>" + m.Groups(3).ToString + "</a>" + LinkCreate(m.Groups(4).ToString);
}
}
}