Hi,
Please find attached a file. Here, starting from the first line, for each 10 lines, I want the next 33 line values to be stored in a text file.I want this to repeat till the end of the file. First 9 lines should be neglected and the next 33 lines should be stored in a file.
Could anybody please provide me with the code for this..
-Saketh.
Loading
FroglegPosted Apr 11, 2011, 8:48 PM
public void readWriteFile()
{
int txtLines = File.ReadAllLines(@"test.txt").Length;
string[] str = new string[txtLines ];
using (StreamReader sr = new StreamReader("test.txt"))
{
for (int i = 0; i < txtLines; i++)
{
str[i] = sr.ReadLine();
}
using (StreamWriter sw = new StreamWriter("test2.txt"))
{
for (int i = 9; i < txtLines; i++)
{
sw.WriteLine(str[i]);
}
}
}
}
edit here for vb
Sub readWriteLine()
Dim txtLines As Integer = File.ReadAllLines("test.txt").Length
Dim str(txtLines) As String
Dim i As Integer = 0
Using sr As New StreamReader("test.txt")
Do Until i = txtLines
str(i) = sr.ReadLine()
i += 1
Loop
End Using
i = 9
Using sw As New StreamWriter("test2.txt")
Do Until i = txtLines
sw.WriteLine(str(i))
i += 1
Loop
End Using
End Sub