【发布时间】:2016-05-01 17:18:04
【问题描述】:
net web 项目我正在尝试插入带有 3 段的文本的所有单词。如果句子是这样的,但是
“此文本是测试文本。”
然后最后一个词带点进入数据库。 (文字。)
strNew = strNew.Trim(new Char[] { ' ', ',', '.', '?' });
我已经尝试过这段代码,但没有帮助。这是我的所有代码。
{int id = 0;
ListBox1.Items.Clear();
string strNew = Request.Form["TextBox1"];
int n = strNew.Split(' ').Length;
ListBox3.Items.Add(String.Format("Number of Words: {0}", n));
int m = Regex.Matches(strNew, "[^\r\n]+((\r|\n|\r\n)[^\r\n]+)*").Count;//Counts Number of Paragraphes
ListBox3.Items.Add(String.Format("Number of Paragraphes: {0}", m));
strNew = strNew.ToLower();// all lower case
strNew = strNew.Trim(new Char[] { ' ', ',', '.', '?' });
var results = strNew.Split(' ').Where(x => x.Length > 1)
.GroupBy(x => x)
.Select(x => new { Count = x.Count(), Word = x.Key });//splitting sentences in to words
using (con){
con.Open();
foreach (var item in results) {//here trying to insert word its id and some other informations but for now they can stay null(yes,null allowed for them)
id++;
string w = item.Word.ToString();
SqlCommand cmd= con.CreateCommand();
cmd.Parameters.AddWithValue("@id", id);
cmd.Parameters.AddWithValue("@word", item.Word);
cmd.CommandText= "INSERT INTO word(id, word, sid, frequency, weight, f) VALUES (@id, @word, 0, 0, 0, 0) ";
cmd.ExecuteNonQuery();
}
con.Close();
} }
【问题讨论】: