Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
hi..
I'm reading .csv excel file and i want to count first word length if first word length exactly contains 2 letters then show result .

What I have tried:

C#
private void button5_Click(object sender, EventArgs e)
 {
            result.Clear();
            OpenAndParseFile("DOW30.csv");
            string text = textBox1.Text;
 var r = from DowStock item in result where item.coName ? select item;
            label1.Text = s.ToList().ToString();
            dataGridView1.DataSource = r.ToList();
            dataGridView1.Columns[0].Width = 160;
            dataGridView1.Columns[1].Width = 155;
            dataGridView1.Columns[2].Width = 155;
            dataGridView1.Columns[3].Width = 155;
            dataGridView1.Columns[4].Width = 155;
            dataGridView1.Columns[5].Width = 155; 
           
        }

How can i do this.Show all Dow companies whose stock symbol is exactly 2 characters (such as BA, KO, GE, etc.).Here is table(column) .LINK which i want to count first word letter if two then show result
Posted
Updated 9-Dec-16 1:39am

Well, your example code sucks in terms of giving us what we need to be more precise in our answers, but I think this might do it...

C#
var r = result.Where(x=>x.coName.Length == 2);


EDIT =====================

C#
var r = result.Where(x=>x.Split(' ')[0].Length == 2);
 
Share this answer
 
v4
Comments
Hameed Khan 9-Dec-16 7:44am    
i think this one query calculate the whole length not first word length?
Hameed Khan 9-Dec-16 7:46am    
sorry it will calculate the whole length of string.I just need to check the first word length if first word before space contain two letters then show related data against this column
#realJSOP 9-Dec-16 7:59am    
Seriously man, you gotta at least put some effort into learning about the .net framework.

I edited my response.
C#
var r = from DowStock item in result 
        where item.coName.Value.ToString().Length == 2 
        select item;
 
Share this answer
 
v2
Comments
Hameed Khan 9-Dec-16 7:46am    
sorry it will calculate the whole length of string.I just need to check the first word length if first word before space contain two letters then show related data against this column

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900