gpt4 book ai didi

c# - 需要解析一个字符串直到文件末尾

转载 作者:太空宇宙 更新时间:2023-11-03 14:31:43 24 4
gpt4 key购买 nike

我有以下代码..我需要按照下面显示的注释代码循环遍历文件末尾我该怎么做?

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();

关于c# - 需要解析一个字符串直到文件末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2426885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com