Word frequency statistics (WEB) edition

Source: Internet
Author: User

Demand:

On the basis of the previous migration of the program to the Web platform, through the user upload txt way to receive files.

Front page code:

<%@ page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%><! DOCTYPE html>

Page display:

Background Management code:

Using system;using system.collections;using system.configuration;using system.data;using System.Linq;using System.web;using system.web.security;using system.web.ui;using system.web.ui.htmlcontrols;using System.web.ui.webcontrols;using system.web.ui.webcontrols.webparts;using system.xml.linq;using System.Text;using System.collections.generic;using System.io;public partial class _default:system.web.ui.page{protected void Page_Load    (object sender, EventArgs e)            {} protected void Button1_Click (object sender, EventArgs e) {if (fileupload1.hasfiles) {            int n = 0;            String strfile = FileUpload1.PostedFile.FileName;            String Strout;            StreamReader sr = File.OpenText (strfile); String input = Sr.            ReadToEnd (); Sr.            Close ();            Response.Write (input); char[] Text = input.            ToCharArray ();            dictionary<string, int> map = new dictionary<string, int> (); for (int i = 0; I < text. Length;                i++) {string s = ""; while (I < text. Length && ((Text[i] >= ' A ' && text[i] <= ' z ') | | (Text[i] >= ' A ' && text[i] <= ' Z ') | |                        Text[i] = = '-')} {if (Text[i] >= ' A ' && text[i] <= ' Z ')                    s + = (Text[i] + 32);                    else S + = text[i];                i++; } if (!map.                    ContainsKey (s)) {if (s = = "") continue;                    n++; Map.                ADD (S, 1);                } else {map[s]++;            }} strout = "";            Strout = "Total number of times:" + n.tostring () + "\ n";            list<keyvaluepair<string, int>> myList = new list<keyvaluepair<string, int>> (map); Mylist.sort (Delegate (Keyvaluepair<string, int> S1, keyvaluepair<string, int> S2) {return s2.Value.CompareTo (S1.            Value);            }); Map.            Clear (); foreach (keyvaluepair<string, int> pair in myList) {Strout = Strout + pair. Key + "" + Pair.                Value + "\ n"; Dic. ADD (pair. Key, pair.            Value);        } TextBox1.Text = Strout; }    }}

Operation Result:

Https:https://git.coding.net/ziyoujay/cipintongji_web.git

Ssh:[email Protected]:ziyoujay/cipintongji_web.git

Word frequency statistics (WEB) edition

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.