Wikipedia:Projekt DotNetWikiBot Framework/GameOnBot/Syntaxfel/090 - Defaultsort lowercase
Utseende
//Originally made by sv:Användare:GameOn in 2011 using System; using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Collections; using System.Xml; using DotNetWikiBot; using System.Threading; using System.Net; using System.Web; class MyBot : Bot { static string upCase(string tmpStr) { char[] arr = tmpStr.ToCharArray(); if (arr.Length >= 1) { if (char.IsLower(arr[0])) arr[0] = char.ToUpper(arr[0]); } for (int i = 1; i < arr.Length; i++) { if (arr[i - 1] == ' ') if (char.IsLower(arr[i])) arr[i] = char.ToUpper(arr[i]); } return new string(arr); } public static void Main() { Site site = new Site(wiki, username, password); String editCommentStr = "Fixar syntaxfel 090: Standardsortering med gemener"; String orgStr; PageList pl = new PageList(site); int startPos; int stopPos; string tmpStr; string tmpStr2; pl.FillFromFile("test1.txt"); pl.FilterNamespaces(new int[] {0}); foreach(Page myPage in pl) { myPage.Load(); orgStr = myPage.text; startPos = myPage.text.IndexOf("{{DEFAULTSORT:"); if(startPos < 0) startPos = myPage.text.IndexOf("{{STANDARDSORTERING:"); if(startPos >= 0) { tmpStr = myPage.text.Substring(startPos); stopPos = tmpStr.IndexOf("}}"); tmpStr = tmpStr.Substring(0, stopPos + 2); tmpStr2 = tmpStr.Substring(tmpStr.IndexOf(":") + 1); tmpStr2 = tmpStr2.ToLower(); tmpStr2 = upCase(tmpStr2); tmpStr2 = tmpStr.Substring(0, tmpStr.IndexOf(":") + 1) + tmpStr2; myPage.text = myPage.text.Replace(tmpStr, tmpStr2); if(myPage.text != orgStr) { myPage.Save(myPage.text, editCommentStr, true); Thread.Sleep(60000); } } } } }