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.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
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.
Answer accepted by question author
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.