Advertisement
Guest User

ReplaceHTML.cs

a guest
Feb 1st, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. class ReplaceHTML
  5. {
  6.     static void Main()
  7.     {
  8.         string text = @"<p>Please visit <a href=""http://academy.telerik.com"">our site</a> to choose a training course. Also visit <a href=""www.devbg.org"">our forum</a> to discuss the courses.</p>";
  9.  
  10.         foreach (Match match in Regex.Matches(text, "<a href=\"(.*?)\">(.*?)</a>"))
  11.         {
  12.             string link = match.Groups[1].Value;
  13.             string word = match.Groups[2].Value;
  14.  
  15.             text = Regex.Replace(text, "<a href=\"" + link + "\">" + word + "</a>", "[URL=" + link + "]" + word + "[/URL]");
  16.         }
  17.         Console.WriteLine(text);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement