Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
How to put the first line of text file in the end position
Hesham Hassanein
Sep 21 2016 12:36 PM
330
Reply
I have a streamwriter. I wrote into a text file all lines but I want to put the first line in the last position of the text file. After writing the stream, i want to switch first line to the last but the first line should not be left blank but to shift the preceeding lines up and then write the stream again. How can i Hold the first line in a variable and start writing from second line and in which part of the code. Thanks in Advance
using
(System.IO.StreamWriter file =
new
System.IO.StreamWriter(filepath))
{
string
[] buffer =
new
string
[count];
while
(!(lines = reader.ReadLine()).Contains(
"Records"
))
{
for
(
int
i = 0; i < count - 1; i++)
{
string
[] fields = lines.Split(
'|'
);
Result[i, 0] =
""
;
Result[i, 1] = fields[1];
Result[i, 2] =
" "
;
Result[i, 3] = xx;
Result[i, 4] =
""
;
Result[i, 5] = fields[4];
Result[i, 6] =
""
;
Result[i, 7] = fields[0];
Result[i, 8] =
""
;
if
(fields[15].Contains(
"PASS"
))
{
Result[i, 9] =
"P"
;
}
else
if
(fields[15].Contains(
"FAIL"
))
{
Result[i, 9] =
"F"
;
}
Result[i, 10] =
""
;
Result[i, 11] =
""
;
Result[i, 12] =
""
;
Result[i, 13] =
""
;
Result[i, 14] =
""
;
}
}
else
if
(fields.Length == 7)
{
Result[i, 1] = "";
Result[i, 2] = "";
Result[i, 3] = fields[0];
//Test Code
Result[i, 4] =
"1"
;
// Test Channel
Result[i, 5] =fields [4];
// Test Value
Result[i, 6] =
"0"
;
//Test Frequency
if
(fields[5].Contains(
"PASS"
))
{
Result[i, 7] =
"P"
;
}
else
if
(fields[5].Contains(
"FAIL"
))
{
Result[i, 7] =
"F"
;
}
Result[i, 8] =
"0"
;
// Test Volt
Result[i, 9] = fields[1];
Result[i, 10] =
"0.0"
;
}
}
Result[i, 11] =
"0"
;
Result[i, 12] =
"1"
;
Result[i, 13] =
"1"
;
Result[i, 14] =
"0"
;
Result[i, 15] = Profile_Index.ToString();
}
result = (
"PATS_TEST"
+
","
+ Result[i, 1] +
","
+ Result[i, 2] +
","
+ Result[i, 3] +
","
+ Result[i, 4] +
","
+ Result[i, 5] +
","
+ Result[i, 6] +
","
+ Result[i, 7] +
","
+ Result[i, 8] +
","
+ Result[i, 9] +
","
+ Result[i, 10] +
","
+ Result[i, 11] +
","
+ Result[i, 12] +
","
+ Result[i, 13] +
","
+ Result[i, 14] +
","
+ Result[i, 15]);
if
(fields[0].Contains(
"END-OF-LINE"
))
{
result = (
"END-OF-LINE"
);
}
}
Profile_Index++;
// Console.WriteLine(result);
file.WriteLine(result);
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
Differnece between method and function
delete label quantity