Rosetta Code/Count examples: Difference between revisions
Content added Content deleted
(added c#) |
m (bugfix) |
||
Line 44: | Line 44: | ||
class Program { |
class Program { |
||
static List<string> GetTitlesFromCategory(string category) { |
static List<string> GetTitlesFromCategory(string category, WebClient wc) { |
||
string content = |
string content = wc.DownloadString( |
||
String.Format("http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:{0}&cmlimit=500&format=json", category) |
String.Format("http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:{0}&cmlimit=500&format=json", category) |
||
); |
); |
||
return new Regex("\"title\":\"(.+?)\"").Matches(content).Cast<Match>().Select(x => x.Groups[1].Value).ToList(); |
return new Regex("\"title\":\"(.+?)\"").Matches(content).Cast<Match>().Select(x => x.Groups[1].Value.Replace("\\/", "/")).ToList(); |
||
} |
} |
||
static string GetSourceCodeFromPage(string page) { |
static string GetSourceCodeFromPage(string page, WebClient wc) { |
||
return |
return wc.DownloadString( |
||
String.Format("http://www.rosettacode.org/w/index.php?title={0}&action=raw", page) |
String.Format("http://www.rosettacode.org/w/index.php?title={0}&action=raw", page) |
||
); |
); |
||
Line 59: | Line 59: | ||
static void Main(string[] args) { |
static void Main(string[] args) { |
||
WebClient wc = new WebClient(); |
|||
List<Task> tasks = new List<Task>(); |
List<Task> tasks = new List<Task>(); |
||
List<string> tasknames = GetTitlesFromCategory("Programming_Tasks"); |
List<string> tasknames = GetTitlesFromCategory("Programming_Tasks", wc); |
||
foreach (string task in tasknames) { |
foreach (string task in tasknames) { |
||
string content = GetSourceCodeFromPage(task); |
string content = GetSourceCodeFromPage(task, wc); |
||
int count = new Regex("=={{header", RegexOptions.IgnoreCase).Matches(content).Count; |
int count = new Regex("=={{header", RegexOptions.IgnoreCase).Matches(content).Count; |
||
Task t = new Task(task, count); |
Task t = new Task(task, count); |