string[] arr = s.Split (',');
第二步,用Dictionary(TKey,TValue)實例化。
代碼如下:
Dictionary<string, int> Statistics = new Dictionary<string, int>();
第三步,統計:
代碼如下:
foreach (string w in arr)
{
if (Statistics.ContainsKey(w))
{
Statistics[w] += 1;
}
else
{
Statistics[w] = 1;
}
}
寫完以上代碼算是大功告成。
但Insus.NET還是要把統計的結果顯示出來:
.aspx:
代碼如下:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1" cellpadding="1" cellspacing="0">
<tr>
<td>字符 </td>
<td>次數 </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();
}
結果:
如果你想看看MS SQL Server版本 可以查看 //www.gxlcms.com/article/30212.htm聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com