Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 需要解析字符串直到文件结束_C#_Asp.net_String - Fatal编程技术网

C# 需要解析字符串直到文件结束

C# 需要解析字符串直到文件结束,c#,asp.net,string,C#,Asp.net,String,我有下面的代码..我需要按照下面显示的注释代码循环文件的结尾,我怎么做 namespace BVParser { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { StreamReader sr = new StreamReader(@"D:\Jaison\J

我有下面的代码..我需要按照下面显示的注释代码循环文件的结尾,我怎么做

namespace BVParser
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            StreamReader sr = new StreamReader(@"D:\Jaison\JaisonWorking\EmailParse\Sample.BV.application.Mails\Sample.BV.application.Mails\ToTest\Test\SourceAscii.msg", Encoding.Unicode);
            string message = sr.ReadToEnd();
            StreamWriter sw = new StreamWriter(@"D:\Jaison\JaisonWorking\EmailParse\Sample.BV.application.Mails\Sample.BV.application.Mails\ToTest\Test\DestAsciiOutNewWOEncodingUnicode.txt");
            sw.Write(message);
            sw.Close();
            sr.Close();
            // StreamReader srseek = new StreamReader(@"D:\Jaison\JaisonWorking\EmailParse\Sample.BV.application.Mails\Sample.BV.application.Mails\ToTest\Test\DestAsciiOutNewWOEncodingUnicode6.txt");

            FileStream fs = new FileStream(@"D:\Jaison\JaisonWorking\EmailParse\Sample.BV.application.Mails\Sample.BV.application.Mails\ToTest\Test\DestAsciiOutNewWOEncodingUnicode6.txt", FileMode.Open, FileAccess.Read);
            StreamReader r = new StreamReader(fs);
            int index = message.IndexOf("prod-");
            //Label2.Text = index.ToString();
            Cluster.Text = message.Substring(index + 5, 2);
            int indexend = message.IndexOf(" ", index);
            int indexdiff = indexend - index;
            Servers.Text = message.Substring(index, indexdiff);

           // Loops should start here.. checking indexat("EOF")  

          While ()
          {
             int exindex = message.IndexOf("Exception:");
                int checkspace = exindex;
                checkspace--;
                if (checkspace == ' ')
                {
                    exindex = message.IndexOf("Exception:", exindex);
                }

                int trav = exindex;
                while (message[trav] != '.') // || message[trav] != ' '
                {
                    trav--;
                }

                int expdiff = exindex - trav + 9;
                Exceptions.Text = message.Substring(trav, expdiff);
                int lastdescindex = message.IndexOf('\n', exindex);
                int firstdescindex = exindex + 10;
                int diffdesc = lastdescindex - firstdescindex;
                Desc.Text = message.Substring(firstdescindex, diffdesc);

            // } Loop should end here.


            fs.Close();

        }
    }
}

这是我做过的事情的一个例子

    StreamReader reader = File.OpenText(filename);
    string line = null
    while ((line = reader.ReadLine()) != null)
    {
    // ... your stuff here
    }
    reader.Close();
    reader.Dispose();
我还建议使用一个。 由于它是,您还可以使用“using”语句构造它:

using (var reader = new StreamReader(path))
{
    string line = null
    while ((line = reader.ReadLine()) != null)
    {
        // do something
    }
}

无法将类型“int”隐式转换为“bool”,但此处的上下文不同..我正在使用文件流分析字符串。。。我想在我提到循环的地方再次迭代解析过程..直到到达文件末尾..参见上面的注释删除了我答案的顶部..我正在考虑另一种类型的阅读器。剩下的部分应该是你要找的。