|
At the risk of sounding stupid, why don't you do it two phases:
1. Read the file into a datatable, adding an additional column to represent a line number
2. Sort the table by line number (desc) and loop through.
Edward
Edward Steward
edwardsteward@optusnet.com.au
|
|
|
|
|
Just read the file into an array of lines, and loop backwards to the first occurrence of the delimiter (exit 1), keep track of the index you found and go from there.
Dybs
|
|
|
|
|
//initialize streamreader
StreamReader myStream = new StreamReader(@"c:\myfile.txt");
//read all the contents and store in string
string WholeFileString=myStream.ReadToEnd();
//convert to array
char []strArray = WholeFileString.ToCharArray();
//reverse the array
Array.Reverse(strArray);
//again convert to string
string newStr = new string(strArray);
//specify the split array (Note \r\n must be specified reverse becoz
string is reverse
char [] split = new char[2];
split[0] = '\n';
split[1] = '\r';
//receive the string array after spliting
string [] Lines = newStr.Split(split);
lines[0] = ; //last line of the file
lines[lines.Length-1] = ; //first line of the file
Regards,
Punithkumar
|
|
|
|
|
|
#define TRUE (C > C#)
|
|
|
|
|
A programmer told me he just learned try...catch, and found it's very powerful. Later, he found one of his methods always return null after he implemented try...catch. Here is his code:
private DataSet GetData()
{
DataSet ds = null;
try
{
ds = new DataSet();
}
catch
{
}
finally
{
ds = null;
}
return ds;
}
|
|
|
|
|
That said, I suggest you and your cow-orker might want to start by learning what the finally block does.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
You are as funny as the programmer. Did you think I am looking for help from you? Read my post again carefully please!
|
|
|
|
|
hmmmm .... this how he read the post ...
try
{
CheckIfPostIsInCorrectForum();
}
catch
{
WriteWrongPostMessage();
}
finaly
{
WriteWrongPostMessageExt();
}
*hehe*
|
|
|
|
|
I think this post is really on thr right forum
It gave me a laught
Sérgio Lima
Many people would sooner die than think; In fact, they do so.
- Bertrand Russell
|
|
|
|
|
Ummm, it is in the correct forum. The posted code is somewhat a horror.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
This post is definitely in the correct forum. The poster knows what is wrong with the code. The person that is new to try/catch/finally doesn’t realize it yet
|
|
|
|
|
Your programmer didn't learn try...catch as well as he thought he did.
Imagine that you are hired to build a bridge over a river. The river gets slightly wider every day; sometimes it shrinks but nobody can predict when. Your contract says you can't use concrete or steel - the client only provides timber and cut stone (but won't tell you what kind). Gravity changes from hour to hour, as does the viscosity of air. Your only tools are a hacksaw, a chainsaw, a rubber mallet, and a length of rope.
Welcome to my world.
-Me explaining my job to an engineer
modified on Thursday, June 26, 2008 11:26 AM
|
|
|
|
|
Robert Royall wrote: Imagine that you are hired to build a bridge over a river. The river gets slightly wider every day; sometimes it shrinks but nobody can predict when. Your contract says you can't use concrete or steel - the client only provides timber and cut stone (but won't tell you what kind). Gravity changes from hour to hour, as does the viscosity of air. Your only tools are a hacksaw, a chainsaw, a rubber mallet, and a length of rope.
Welcome to my world.
Very true. I like that.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
"A little knowledge is a dangerous thing." -- Alexander Pope
|
|
|
|
|
Just to be pedantic - Pope's quotation is actually "A little learning is a dangerous thing"
====================================
Transvestites - Roberts in Disguise!
====================================
|
|
|
|
|
Since some experienced programmers like Dan Neely didn't get humor feeling from my post, I do need to add the following words at the bottom of my post:
(Hint: the programmer set ds = null in section finally before returning his ds)
|
|
|
|
|
You could edit your post.
Just make it clear(er) that you have already pointed out the error and are not asking for help.
|
|
|
|
|
I think a coding horror and a common mistake when misunderstanding the functionality of the language are often confused. Not reading the documentation is an entirely different problem!
If this developer had been coding for years, and only just come across try..catch..finally, then I would truly cry, but if this is a newbie, this is a case of being too harsh on your underlings (like the post the other day)
|
|
|
|
|
che3358 wrote: (Hint: the programmer set ds = null in section finally before returning his ds)
That was one of the first things I noticed
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
He should have learned try-catch-finally, not just try-catch.
|
|
|
|
|
che3358 wrote: A programmer student told me he just learned was just starting to learn try...catch
|
|
|
|
|
cause:
finally
{
ds = null;
}
|
|
|
|
|
I think we knew that already
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
A simple programming oversight.
So the creationist says: Everything must have a designer. God designed everything.
I say: Why is God the only exception? Why not make the "designs" (like man) exceptions and make God a creation of man?
|
|
|
|