首页 > 解决方案 > 将字符串拆分为行并使用.net检查当前行和下一行

问题描述

在将字符串拆分为带有 '\n' 的行之后,当您已经在检查当前行时,如何获得下一行的内容?现在这就是我在 .net 中使用的内容:

 WebClient Downloadurl = new WebClient();
            byte[] myDataBuffer = Downloadurl.DownloadData(url);
            string download = Encoding.ASCII.GetString(myDataBuffer);
            String newfile = download.Replace("<br>", "\n");

            String path = @"E:\BI\projet\dotnet2.csv";
            try
            {
                 Create the file, or overwrite if the file exists.
                using (FileStream fs = File.Create(path))
                {
                    byte[] info = new UTF8Encoding(true).GetBytes(newfile);
                    fs.Write(info,0,info.Length);
                }

标签: .netstringfilecsv

解决方案


我能够找到如下所示的解决方案

            StreamReader st = new StreamReader(path);
        while (!st.EndOfStream)
        {
            var slpits = st.ReadLine();
            String type = slpits.Substring(0,4);

            if (type =="TICN" )
            {
                 ticketid = slpits.Substring(5, 21);
            }

            if (type =="SCON")
            {
                slpits =  slpits.Insert(5, ticketid);
            }

推荐阅读