Menu

Problems with adding/removing categories

Help
Kbdank71
2008-08-11
2013-05-13
  • Kbdank71

    Kbdank71 - 2008-08-11

    When renaming categories, my bot treats it as a remove/add.  First it checks to see if the article is already in category 2, in which case it just removes it from 1.  If it's not in 2, it replaces category 1 with category 2.

    The code:
    -----
    pl3[i].Load();  //loads article
    if (Regex.IsMatch(pl3[i].text, @"(?i)\[\[(" + site.namespaces["14"] + "|" + Site.wikiNSpaces["14"] + ") *: *" + pl[1].title + @" *(]]|\|)"))  //checks to see if article is already in category 2
    {
        pl3[i].RemoveFromCategory(pl[0].title);  //removes it if it is
    }
    else
    {
        pl[0].RemoveNSPrefix();
        pl[1].RemoveNSPrefix();
        pl3[i].text = pl3[i].text.Replace("[[Category:" + pl[0].title,"[[Category:" + pl[1].title);  //replaces category 1 with category 2
    -----

    My problem occurs when category 1 is different than category 2 by capitalization only (for example, changing Category:Foo bar to Category:Foo Bar).  On the first article, it works fine.  But for every other article, it simply removes category 1. 

    I think the problem is due to RemoveNSPrefix.  If I don't use it, the replace doesn't work. 

    Any ideas?

     
    • CodeDriller

      CodeDriller - 2008-08-12

      Try removing (?i) inline option from first regular expression. That (?i) means "IgnoreCase". I think that is the reason of malfunction.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.