2016-03-29 21 views
0

Bir metin dosyasından tekrarlanan kelimeleri saymaya çalışıyorum ve bu hatayı alıyorum tanımını içermiyor .lines için ad system.windows.forms olduğunu ... ve ben zaten kullanmıştı ... bu yüzden ... yanlış yerine Hatlarısystem.web.ui.webcontrols.textbox "satırları"

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Text.RegularExpressions; 
using System.Windows.Forms; 
using System.IO; 

public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
    } 

    protected void Click_Click(object sender, EventArgs e) 
    { 
     TextBox1.Lines =File.ReadAllLines("D:\\mun.txt") 
     Regex regex = new Regex("\\w+"); 

     var frequencyList = regex.Matches(TextBox1.Text) 
           .Cast<Match>() 
           .Select(c => c.Value.ToLowerInvariant()) 
           .GroupBy(c => c) 
           .Select(g => new { Word = g.Key, Count = g.Count() }) 
           .OrderByDescending(g => g.Count) 
           .ThenBy(g => g.Word); 

     Dictionary<string, int> dict = frequencyList.ToDictionary(d => d.Word, d => d.Count); 

     foreach (var item in frequencyList) 
     { 
      Label1.Text =Label1.Text+item.Word+"\n"; 
      Label2.Text = Label2.Text+item.Count.ToString()+"\n"; 
     } 
    } 
} 
+0

gösterilecek <br /> kullanıyor. Hata cevabı söylüyor. – Hendry

cevap

2

Satırları gidiyorum nereye kimse bana yol eğer. Satırlar özelliğini ayarlamak için okuduğunuz dizinin uzunluğuna ihtiyacınız vardır. ReadAllLines ile başladığınızdan beri, satırları tek bir dizeyle ilişkilendirerek tüm içeriği geri yüklemeniz gerekir. HTML sizi `TextBox`` System.Web.UI.WebControls` ad kullanarak altında olduğu için yeni bir satırını

protected void Click_Click(object sender, EventArgs e) 
{ 
    string[] lines = File.ReadAllLines("D:\\mun.txt"); 
    var content = String.Join(System.Environment.NewLine, lines); 
    TextBox1.Rows = lines.Length; 
    TextBox1.Text = content; 

    Regex regex = new Regex("\\w+"); 
    var frequencyList = regex.Matches(content) 
     .Cast<Match>() 
     .Select(c => c.Value.ToLowerInvariant()) 
     .GroupBy(c => c) 
     .Select(g => new { Word = g.Key, Count = g.Count() }) 
     .OrderByDescending(g => g.Count) 
     .ThenBy(g => g.Word); 
    Dictionary<string, int> dict = frequencyList.ToDictionary(d => d.Word, d => d.Count); 

    foreach (var item in frequencyList) 
    { 
     Label1.Text = Label1.Text + item.Word + "<br />"; 
     Label2.Text = Label2.Text + item.Count.ToString() + "<br />"; 
    } 
} 
+1

Teşekkürler kardeşim çalıştı ... :) –