问题描述
我正在尝试从某些标头的文本文件值读取失败,例如:
if(line.Substring(0,18)=="请求类型 :"))
{
RequestType = line.Substring(21,60);
}
私有void mnuopenRequest_Click(对象发送者,EventArgs e)
{
opnTextFile.Filter =仅文本文件(* .txt)| * .txt |" +"所有文件(*.*)| *.*" ;;
opnTextFile.ShowDialog();
字符串line =";
TextReader tr;
如果(opnTextFile.FileName!='')
{
试试
{
tr = File.OpenText(opnTextFile.FileName);
而(true)
{
行= tr.ReadLine();
如果(行!=空)
{
txtRequest.Text + = line +"\ r \ n";
if(line.Substring(0,18)=="请求类型 :"))
{
RequestType = line.Substring(21,60);
}
//tr.Close();
}
其他
{
返回;
//tr.Close();
}
//tr.Close();
}
//tr.Close();
}
catch(异常)
{
MessageBox.Show(打开文件时出错");
}
}
}
I am trying to read from text file values of some headers with failure like this :
if (line.Substring(0, 18) == "Request Type :")
{
RequestType = line.Substring(21, 60);
}
private void mnuopenRequest_Click(object sender, EventArgs e)
{
opnTextFile.Filter = "Text Files Only (*.txt)|*.txt|" + "All Files (*.*)|*.*";
opnTextFile.ShowDialog();
string line="";
TextReader tr;
if (opnTextFile.FileName != "")
{
try
{
tr = File.OpenText(opnTextFile.FileName);
while (true)
{
line = tr.ReadLine();
if (line != null)
{
txtRequest.Text += line+"\r\n";
if (line.Substring(0, 18) == "Request Type :")
{
RequestType = line.Substring(21, 60);
}
// tr.Close();
}
else
{
return;
// tr.Close();
}
// tr.Close();
}
//tr.Close();
}
catch (Exception)
{
MessageBox.Show("Error opening file");
}
}
}
推荐答案
喜欢什么?我看不到任何失败的描述.
我们应该猜测发生了什么以及代码中的什么地方吗?
-韦恩
Like what? I don't see any description of a failure.
Are we supposed to guess what's happening and where in your code?
- Wayne
这篇关于从文本文件读取标题/字段失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!