Switch lines

gerlatie

New member
Joined
Mar 1, 2016
Messages
3
Programming Experience
Beginner
How do i get line 13 between 12 and 14.

11 750080770160301
12 750080770160301
14 750080770160301
14 750080770160301
11 750080770160301
12 750080770160301
13 750080770160301
14 750080770160301
14 750080770160301
14 750080770160301
14 750080770160301
13 750080770160301
 
To be clear, are you saying that you want to get a row that starts with "13" if and only if the preceding row starts with "12" and the following row starts with "14"? Do you just want to get the first one or all of them if there are multiple? Where exactly are these lines? In a file? In a String? Somewhere else? Code can't be "fuzzy", it must be precise, so you have to provide all the relevant information.
 
The input file is
11
12
13
14
14
11
12
13
14
14
14


Output should be the same but in line 13 should be the count of how many lines that starts with 14

the output file should be

11
12
13 2
14
14
11
12
13 3
14
...
                    while (!reader.EndOfStream)
                    {
                        do
                        {
                            read = reader.ReadLine();
                            if (read.Substring(0, 2) == "11")
                            {
                               write.WriteLine(read);
                            }
    
                            if (read.Substring(0, 2) == "12") 
                            {
                                write.WriteLine(read);
                            }
                        } while (read.Substring(0, 2) != "14");
                        if (read.Substring(0, 2) == "14" || read != null)
                        {
                            teller++;
                            codes[0] = "14" ;
                        }
                        if ((read.Substring(0, 2) == "13")
                        {
                            schrijven = "11" + Environment.NewLine + "12" + Environment.NewLine + "13" + teller;
                            write.WriteLine(schrijven);
                            teller = 0;
                        }
                        
                        foreach (string i in codes)
                        {
                            write.WriteLine(i);
                        }
 
                    }
 
Last edited by a moderator:
Firstly, I have fixed the formatting of your code snippet. Please use formatting tags when posting code in future.

Secondly, what you say you want in your second post is not the same as what you said you wanted in your first post. Not only that, neither match the thread title and what you say you want in your second post is not what you show you want. It's like you're trying to make this as confusing as possible. Please provide a FULL and CLEAR explanation of EXACTLY what you want.
 
Back
Top Bottom