string[] arr = s.Split (',');
第二步,用Dictionary(TKey,TValue)實(shí)例化。
代碼如下:
Dictionary<string, int> Statistics = new Dictionary<string, int>();
第三步,統(tǒng)計(jì):
代碼如下:
foreach (string w in arr)
{
if (Statistics.ContainsKey(w))
{
Statistics[w] += 1;
}
else
{
Statistics[w] = 1;
}
}
寫(xiě)完以上代碼算是大功告成。
但I(xiàn)nsus.NET還是要把統(tǒng)計(jì)的結(jié)果顯示出來(lái):
.aspx:
代碼如下:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1" cellpadding="1" cellspacing="0">
<tr>
<td>字符 </td>
<td>次數(shù) </td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("key") %>
</td>
<td>
<%# Eval("value") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
.aspx.cs:
代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
this.Repeater1.DataSource = Statistics;
this.Repeater1.DataBind();
}
結(jié)果:
如果你想看看MS SQL Server版本 可以查看 //www.gxlcms.com/article/30212.htm聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com