I'll be honest with you; I think I have accomplished exactly what you are asking. I did this in less than 20 lines of code.
The thing is, you've posted beyond a few threads like this, asking us to help you parse\edit some kind of text. I would just rather help guide you through this sort of thing, so you can help yourself better with it next time, than just hand you the code. And believe me, at this point (2:30 AM here), it would certainly be
easier for me to just post the code.
I used a text box and then put the changes back into the text box, but you could just as easily do this from and to a file.
Either way, I put the lines of text into a
string array. This was the
only string array that I used. The variable that holds my output is actually a
generic list of type string. If you are not sharp on Generics, read up on them, they are amazing. In this case, the
Insert method really comes in handy.
The
only other variable is an integer I use to hold the
number of "Txxx" occurrences found, which only is important if you want them in the same order as they were in the file.
For, I will iterate through
each line of the
array that holds my input.
I check
if the
first character
is a "T",
and then I make sure that the next three characters are
numeric.
And finally, I check that the
index of this line in the
array is
greater than the
index of the line "DETECT,ON".
If the line has those three things going for it,
then I will
insert this line into my
generic list of type string, after the
index of the line "FMAT,2" within my input
array and any
other lines that I may have already
inserted as determined by an
integer variable. I will also
add one to the count of this integer variable.
Or
else, if the line does not have those three things going for it, I will just
add this line to my
generic list of type string.
I will then move on to the
next line.
After this is all done, I will
clear my text box and set its
lines property equal to the
generic list of type string, after I convert it
to an
array.
Now, see if you can follow those instructions and the hints to write this code by yourself. At least try and post what you've got because me or somebody else will always be willing to help.
This post has been edited by LoveIsNull: 2 Jul, 2009 - 11:06 PM