开发者

C# streamreader if questions

I'm trying to write out the specific line of code that contains the IF statement. 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. Also, how do i only write out the specific line that meets the if statement. Is there one where i should do a foreach? foreach (redsplitline in redsplitlines)

heres the code:

{
                    string linesplitnew = "ENDOB";
                    string[] redsplitlines = rdrred.ReadToEnd().Split开发者_Python百科(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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜