【发布时间】:2013-12-18 15:09:59
【问题描述】:
你好!我对 C# 完全陌生,需要知道如何逐行读取文件(跳过其中包含制表符的文件)并将文本设置为 RichTextBox! 我一直在这样做:
DialogResult result = open_dialog.ShowDialog();
if (result == DialogResult.OK)
{
string file_name = open_dialog.FileName;
System.IO.StreamReader sr = new System.IO.StreamReader(file_name);
String data;
data = sr.ReadToEnd();
rich_words.Text = data;
String line;
using (var file = System.IO.File.OpenText(fileName))
{
// read each line, ensuring not null (EOF)
while ((line = file.ReadLine()) != null)
{
if(line.Contains('\t'))
//do nothing
else
richbox.Text=line;
}
}
}
但我没有这样做!很伤心,因为我已经尽力了,现在我似乎什么也没做! 我的样本数据是:
生命体征
respirations
vital signs
vital sign checks
vital signs/blood pressure
blood pressure observation
blood pressure
auscultate blood pressures
monitor blood pressure
check blood pressure
blood pressure gauge
监控
monitor skin color
monitor characteristics
monitor pulse
monitor presence
monitor
monitor/monitor temperature
monitor temperature
continuous temperature monitoring device
检查
check body temperature
check frequency
check pain level
special checks
check
check body temperaturewith
上面突出显示的文本有制表符,所以我不需要它们。请为此提出任何解决方案。我只需要像标题这样的词:|生命体征| |监视器|和 |检查|等等...有人可以帮我解决这个问题吗?
【问题讨论】:
-
除非您发布的代码与您的实际代码不同,否则您的富文本框只会显示不包含选项卡的最后一行:
richbox.Text = line;您需要附加 富文本框的每一行 -
不,它根本不工作! :(