C#计算多行文本框中存在的段落数 [英] C# to count number of paragraphs existed in multi-line text-box
本文介绍了C#计算多行文本框中存在的段落数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好小组成员,
我有一个带有多行文本框的表格,当用户单击提交"按钮最后输入数据后,我需要找到多行文本框中存在的段落数.有谁能帮我为此.
谢谢,
MOHAMMAD SIDDIQALI.
Hello Group Members,
I have form with Multi-line text-box,After entering data at the end when the user click''s "Submit" button then I need to find number of paragraph existed in multi-line text box .Can any one help me how to do this.
Thanks,
MOHAMMAD SIDDIQALI.
推荐答案
取决于定义段落的方式-如果段落以期望的方式以ENTER结尾,则很简单:
Depends on how you define a Paragraph - if a paragraph ends with an ENTER as you would expect, then it is simple:
int paragraphs = myTextBox.Lines.Length;
可以尝试一下,
Can Try this,
if (Textbox1.Text != "")
{
int paraCount = Textbox1.Text.Split('\r').Length;
}
try
{
//made by Muhammad Usman-Bahria University-kai
string path = args[0];
FileStream fh = new FileStream(path, FileMode.Open, FileAccess.Read);
int i;
string s = "";
while ((i = fh.ReadByte()) != -1)
{
s = s + (char)i;
}
int count = 0;
for (int j = 0; j < s.Length - 1; j++)
{
if (s.Substring(j, 1) == "\n")
{
count++;
}
}
Console.WriteLine("The total searches were :" + count);
fh.Close();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
这篇关于C#计算多行文本框中存在的段落数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文