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