Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class ReplaceAhrefWithURLTags
- {
- //Write a program that replaces in a HTML document given as string all the tags <a href="…">…</a> with corresponding tags [URL=…]…/URL]. Sample HTML fragment:
- //<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>
- //<p>Please visit [URL=http://academy.telerik. com]our site[/URL] to choose a training course. Also visit [URL=www.devbg.org]our forum[/URL] to discuss the courses.</p>
- static void Main()
- {
- string[] findTags = { "<a href=\"", "\">", "</a>" }; //Strings to find
- string[] replaceTags = { "[URL=", "]", "[/URL]"};//Replace strings
- string htmlText = @"<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>";//Html string to work with: @ to escape the // and double quotes ("") to escape the quotes (").
- for (int i = 0; i < findTags.Length; i++)
- {
- htmlText = htmlText.Replace(findTags[i], replaceTags[i]);//Do the replacements
- }
- Console.WriteLine(htmlText);//Print the result
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement