Thread: Disable href

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Western Isle of Scotland
    Posts
    258
    Rep Power
    17

    Disable href


    Is there a way of disabling a link with C# if a # is used within the link

    <a href="#"></a>

    Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    14
    Rep Power
    0
    First, where is this link? On a webpage in a webbrowser control? I don't understand. I can't assume anything here yet.

    Use Regex and remove all that match a link href for "#".
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Western Isle of Scotland
    Posts
    258
    Rep Power
    17
    Sorry for the late response the links are on the webpage, how would I go about using RegularExpressions to remove these from webpage?

    thanks
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    14
    Rep Power
    0
    Code:
    private void MainMethod()
    {
    	string html = "this is a test <a href=\"#\"># LINK</a> to see...<a href=\"http://www.link.com\">REGULAR LINK</a> ";
    	string s = Regex.Replace(html, "<.*?href=\"#\".*?>(.*?)</a>", new MatchEvaluator(MatchEval), RegexOptions.IgnoreCase);
    	MessageBox.Show(s);
    }
    
    private static string MatchEval(Match m)
    {
    	return m.Groups[1].Value;
    }
    Here's a quick example i've put together for you.

IMN logo majestic logo threadwatch logo seochat tools logo