To implement the first step, you need to Split the string into an array and use the function Split ():
Copy codeThe Code is as follows: string [] arr = s. Split (',');
Step 2: Use Dictionary (TKey, TValue) for instantiation.Copy codeThe Code is as follows: Dictionary <string, int> Statistics = new Dictionary <string, int> ();
Step 3: Statistics:Copy codeThe Code is as follows: foreach (string w in arr)
{
If (Statistics. ContainsKey (w ))
{
Statistics [w] + = 1;
}
Else
{
Statistics [w] = 1;
}
}
The above code is a success.
However, Insus. NET still needs to display the statistical results:
. Aspx:Copy codeThe Code is as follows: <asp: Repeater ID = "Repeater1" runat = "server">
<HeaderTemplate>
<Table border = "1" cellpadding = "1" cellspacing = "0">
<Tr>
<Td> character </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 codeThe Code is as follows: protected void Page_Load (object sender, EventArgs e)
{
This. Repeater1.DataSource = Statistics;
This. Repeater1.DataBind ();
}
Result:
If you want to see ms SQL Server version, you can view http://www.jb51.net/article/30212.htm