Share via

Remove First Line and two first

MiPakTeh 1,476 Reputation points
2022-01-31T15:47:24.65+00:00

Hi All,

I want to remove one line first and two column first.

       private void button5_Click(object sender, EventArgs e)
        {
            //Text File =
             //BTY,Ui,SXC,WE5,EE1
             //042892,19920624,3722,3697,5286
             //042992,19920625,3343,9500,0651
            string a = File.ReadLines(@"C:\Users\family\Documents\Tool_Ori.txt").ToString();


            for (int i = 0; i < a.Length; i++)
            {
                string[] b = a.Split(',');
                string s = b[2];

                s += ',' + b[i];

                listBox5.Items.Add(s);
            }
        }

then listbox5 show;

             //
             //3722,3697,5286
             //3343,9500,0651
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

Viorel 127K Reputation points
2022-01-31T16:08:34.987+00:00

Try something like this:

foreach( var s in 
    File
        .ReadLines( @"... path ..." )
        .Skip( 1 )
        .Select( s => s.Split( new[] { ',' }, 3 )[2] ) )
{
    listBox5.Items.Add( s );
}

If you are interested in Data Binding, then:

listBox5.DataSource =
    File
        .ReadLines( @"... path ..." )
        .Skip( 1 )
        .Select( s => s.Split( new[] { ',' }, 3 )[2] )
        .ToList( );

This assumes that there are enough columns in each line.

You can also use Regular Expressions.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.