Hye there!我對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
突出顯示的文本上面已經制表符,所以我不需要他們。請爲此提出任何解決方案。我只需要這些詞就像標題:|生命體徵| | monitor |並| |檢查|等等...有人可以幫我請這個嗎?
除非你發佈的代碼比你的實際代碼不同,您的富文本框只會顯示不包含選項卡的最後一行:'richbox.Text = line;'您需要**將每個適當的行追加到富文本框 –
不,它不起作用根本! :( – user3115728