I have a lot of text files with values, although the lines in the text file should be partially scrambled.
An example of a text file is as follows: (see the edit for an easier example)
0.00;1.2;3;2015-20-06 13:33:33
0.00;1.2;3;2015-20-06 13:33:34
0.00;1.2;3;2015-20-06 13:33:35
0.00;1.2;3;2015-20-06 13:33:36
[RAND]
0.00;1.2;3;2015-20-06 12:05:05
0.00;1.2;3;2015-20-06 12:05:22
0.00;1.2;3;2015-20-06 12:06:27
0.00;1.2;3;2015-20-06 12:05:42
[/RAND]
0.00;1.2;3;2015-20-06 12:25:36
0.00;1.8;3;2015-20-06 12:26:26
0.00;1.2;3;2015-20-06 12:28:05
[RAND]
0.00;1.8;3;2015-20-06 12:32:22
0.00;1.2;3;2015-20-06 12:33:04
[/RAND]
Everything between [RAND]
and [/RAND]
should be put in a random order.
So far I have the following but I have absolutely no idea how to continue from here or if this is even the right approach.
using (StreamReader reader = new StreamReader(LocalFile))
{
bool InRegion = false;
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.Equals("[RAND]"))
InRegion = true;
if (line.Equals("[/RAND]"))
InRegion = false;
}
}
One of my concerns is that I am using StreamReader and therefor cannot change the file.
There could be 2 lines but also 10 lines inside the RAND
block and multiple RAND
blocks per file.
Could somebody explain me how to go by this?
Thanks a lot in advance.
EDIT:
Easier example:
A
B
C
[RAND]
D
E
F
[/RAND]
G
H
It should then scramble the lines with D, E and F in a random order so you get something as follows:
A
B
C
E
F
D
G
H