To achieve the first step, you need to split the string into an array, and the function you want to use is split ():
Copy Code code as follows:
string[] arr = s.split (', ');
The second step is to instantiate with dictionary (Tkey,tvalue).
Copy Code code as follows:
dictionary<string, int> Statistics = new dictionary<string, int> ();
The third step, statistics:
Copy Code code as follows:
foreach (string w in arr)
{
if (Statistics.containskey (W))
{
STATISTICS[W] + + 1;
}
Else
{
STATISTICS[W] = 1;
}
}
Writing the above code is a complete success.
But Insus.net still have to show the results of the statistics:
. aspx:
Copy Code code as follows:
<asp:repeater id= "Repeater1" runat= "Server" >
<HeaderTemplate>
<table border= "1" cellpadding= "1" cellspacing= "0" >
<tr>
<td> characters </td>
<td> Times </td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval ("key")%>
</td>
<td>
<%# Eval ("value")%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
. Aspx.cs:
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
This. Repeater1.datasource = Statistics;
This. Repeater1.databind ();
}
Results:
If you want to see MS SQL Server version can view http://www.jb51.net/article/30212.htm