I have some text that contains numerous values like so:
PartNumber Description Amount
Fid1 blahblahblah 999934109
0603 moreblah 12
exclude ehh? 981
FID5 fillertext 123
fid2 fillertext 123
fid fillertext 123
0603 fillertext 123
0603 fillertext 123
0603 fillertext 123
0402 fillertext 123
0402 fillertext 123
//etc.........etc............etc
I would like to print out the values that contain “FID”
int j = 1;
foreach (var line in theList)
{
if (line.PartNumber.ToUppeR().Contains("FID"))
{
sw.WriteLine("{0}: {1} {2} {3}",
j,
line.PartNumber,
line.Amount,
line.Description);
j++;
}
}
However, when I do this, it prints them out as follows:
1: Fid1 999934109 blahblahblah
2: FID5 123 fillertext
3: fid2 123 fillertext
4: fid 123 fillertext
and I would like to print them out numerically.. so like this:
1: fid 123 fillertext
2: Fid1 999934109 blahblahblah
3: fid2 123 fillertext
4: FID5 123 fillertext
Is there an easy, quicky way to do this?
You could probably use the orderby clause of a LINQ query against theList:
You wouldn’t need the if statement in your foreach, then, either.