Rosetta Code/Rank languages by popularity: Difference between revisions
Rosetta Code/Rank languages by popularity (view source)
Revision as of 13:09, 11 September 2023
, 8 months ago→{{header|C sharp|C#}}: Handle more that 500 languages and more than 999 tasks
(Updated the URLs. Added a test to extract the title as "Category:" may be missing. Updated the result.) |
(→{{header|C sharp|C#}}: Handle more that 500 languages and more than 999 tasks) |
||
Line 1,176:
=={{header|C sharp|C#}}==
Sorting only programming languages.<br>
Note that this does not distinguish between tasks and non-task categories, so the counts can exceed the total number of tasks.<br>
<syntaxhighlight lang="csharp">using System;▼
Note this may need to set the Security Protocol type to Tls12 - see the section Problem running the C# entry in [[Talk:Rosetta_Code/Count_examples]]
using System;
using System.Collections;
using System.Collections.Generic;
Line 1,188 ⟶ 1,191:
static void Main(string[] args)
{
string
);
ArrayList langs = new ArrayList();
Dictionary<string, int> qtdmbr = new Dictionary<string, int>();
string cmcontinue = "";
MatchCollection match1 = new Regex("\"title\":\"Category:(.+?)\"").Matches(get1);▼
MatchCollection match2 = new Regex("title=\"Category:(.+?)\">.+?</a>[^(]*\\((\\d+) members\\)").Matches(get2);▼
do
foreach (Match lang in match1) langs.Add(lang.Groups[1].Value);▼
{
string get1 = new WebClient().DownloadString("http://www.rosettacode.org/w/api.php?"
+"action=query&list=categorymembers"
+"&cmtitle=Category:Programming_Languages"
+"&cmlimit=500&format=json"
+cmcontinue
);
cmcontinue = "";
MatchCollection cmcontinueMatch = new Regex("cmcontinue\":\"([a-z0-9A-Z|]*)\"").Matches(get1);
foreach (Match more in cmcontinueMatch) cmcontinue = "&cmcontinue=" + more.Groups[1].Value;
}
while( cmcontinue != "" );
MatchCollection match2 =
▲
foreach (Match match in match2)
Line 1,203 ⟶ 1,223:
if (langs.Contains(match.Groups[1].Value))
{
qtdmbr.Add(match.Groups[1].Value, Int32.Parse(match.Groups[2].Value
.Replace(",",string.Empty)
.Replace(".",string.Empty)));
}
}
string[] test =
int count = 1;
Line 1,213 ⟶ 1,236:
foreach (string i in test)
{
Console.WriteLine("{0,
count++;
}
}
}
{{out|Output (as of
<pre>
2. 368 - Python▼
7: 1537 Perl
9: 1376 J
10: 1287 C
. . .
</pre>
===Object-oriented solution===
<syntaxhighlight lang="csharp">using System;
|