我在文本文件中有以下类型的数据:
Accumulated Earnings Tax.
A tax penalty which is imposed on corporate earnings which are retained by the corporation for non-
business related needs.
Acquisition Cost.
The expenses incurred by an insurer or reinsurance company that are directly related to putting the
business on the books of the company. The largest portion of this cost is usually the agent's or sales
representative's commission or bonus.
Act of God.
An event arising out of natural causes with no human intervention which could not have been prevented
by reasonable care or foresight. Examples are floods, lightning, and earthquakes.
Actual Cash Value.
An amount equivalent to the replacement cost of lost or damaged property at the time of the loss, less
depreciation. With regard to buildings, there is a tendency for the actual cash value to closely parallel the
market value of the property. See also Market Value.
每个带有描述的新词都有一个换行符!现在我要做的是读取文件搜索关键字并打印其描述。关键字下但在下一个由换行符标记的单词之前的行。
我开发了一个代码来查找关键字并打印它的描述,但它只打印唯一的一行描述!
我的代码:
int count = 1;
private void openfile_Click(object sender, EventArgs e)
{
if (text.Text == String.Empty)
{
err.SetError(text, "Needs to contain Text");
}
DialogResult result = open_dialog.ShowDialog();
if (result == DialogResult.OK)
{
try
{
string file_name = open_dialog.FileName;
String lines_of_words;
using (var file = System.IO.File.OpenText(file_name))
{
// read each line, ensuring not null (EOF)
while ((lines_of_words = file.ReadLine()) != null)
{
if (lines_of_words.StartsWith(text.Text))
{
Console.WriteLine("TEXT IS YES"+count);
goGetDesc(file_name);
break;
}
else
{
count += 1;
}
}
}
}
catch (Exception ex)
{
}
}
}
private void goGetDesc(String file_name)
{
string[] lines = File.ReadAllLines(file_name);
desc.Text+=(lines[count])+Environment.NewLine; //here i want to print the multiple lines if keyword has multiple lines!
}
假设我想找到关键字“累积所得税。”如果找到它,我想打印该关键字下的所有行,直到 LINE BREAK。