public static void Main()
Console.WriteLine("Hello World");
Console.WriteLine(Linkify("This is a magic word.", "magic"));
Console.WriteLine(Linkify("This is a <a href='/link.html'>magic</a> word.", "magic"));
Console.WriteLine(Linkify("This is a <a href='/link.html'>crazy magic stuff</a> word.", "magic"));
Console.WriteLine(Linkify("This is a normal word", "magic"));
private static string Linkify(string phrase, string word)
int wordIndex = phrase.IndexOf(word);
int linkBeginIndex = phrase.IndexOf("<a href");
int linkEndIndex = phrase.IndexOf("</a>");
if(linkBeginIndex == -1 || !(wordIndex > linkBeginIndex && wordIndex < linkEndIndex))
phrase = phrase.Replace(word, String.Format("<a href='/link.html'>{0}</a>", word));