asp.net calculating the number of occurrences of strings in a string _ Practical tips

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.