简体   繁体   English

C#流阅读器是否有问题

[英]C# streamreader if questions

I'm trying to write out the specific line of code that contains the IF statement. 我正在尝试写出包含IF语句的特定代码行。 What appears to be happening if it never finds the code i'm looking to call in my if statement and i know it exists, it's a copy and paste. 如果它从未在我的if语句中找到我要调用的代码并且我知道它存在,那似乎是正在发生的事情,它是复制和粘贴。 Also, how do i only write out the specific line that meets the if statement. 另外,我如何只写出符合if语句的特定行。 Is there one where i should do a foreach? 有没有应该我做的地方? foreach (redsplitline in redsplitlines) foreach(redsplitlines中的redsplitline)

heres the code: 这是代码:

{
                    string linesplitnew = "ENDOB";
                    string[] redsplitlines = rdrred.ReadToEnd().Split(new string[] { linesplitnew }, StringSplitOptions.None);
                    string redpullline = "*BEGINOB\r\n6*";
                    string redpullline2 = "*BEGINOB\r\n13*";
                    if(redsplitlines.Contains(redpullline))
                    {
                        Console.WriteLine(redsplitlines);
                    }
                    else if(redsplitlines.Contains(redpullline2))
                    {
                        Console.WriteLine(redsplitlines);
                    } 

                }

Try this: 尝试这个:

var lines = from line in redsplitlines
            where line.Contains(redpullline) || line.Contains(redpullline2)
            select line;

foreach (var l in lines)
    Console.WriteLine(l);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM