Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Select the first column

Suddenly I am stucked. Shamed.
Select first column in a text file.
 string[] lines = File.ReadAllLines(inputFile);
                           var list1 = from line in lines
                            let coulmns=line.Split('\t')
                            select columns[0]

Open in new window

????
0
zhshqzyc
Asked:
zhshqzyc
  • 7
  • 2
1 Solution
 
for_yanCommented:

Perhaps
Split("\s+"); or Split("\\s+");
will work ?
0
 
zhshqzycAuthor Commented:
Error      1      The name 'columns' does not exist in the current context      
0
 
for_yanCommented:
In C# I think you dont write "let"
and you need to declare

string [] columns = line.Split("\\s+");
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
for_yanCommented:

this is how it works in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace MyTry
{
    class MyTry
    {
        static void Main(string[] args)
        {
            Console.WriteLine("My try again");
            string line = "sdda\tsadasd sdfds\t sda";
            string[] columns = Regex.Split(line, "\\s+");
            for (int i = 0; i < columns.Length; i++)
            {

                Console.WriteLine(columns[i]);


            }
        }
    }
}

Open in new window

0
 
for_yanCommented:

This is the  output from above code
(My try again is from previous cod - see above,
the rest is from splitting the string)

My try again
sdda
sadasd
sdfds
sda

Open in new window

0
 
zhshqzycAuthor Commented:
I meant that I want to get
My
sdda

Open in new window

The first column.
0
 
for_yanCommented:
This would be one column:

(I omnly was not redaing from file):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace MyTry
{
    class MyTry
    {
        static void Main(string[] args)
        {
                       string line = "sdda\tsadasd sdfds\t sda";
            string[] columns = Regex.Split(line, "\\s+");
            Console.WriteLine(columns[0]);

                 }
    }
}

Open in new window


Output:
sdda

Open in new window

0
 
for_yanCommented:
this is even with reading form file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace MyTry
{
    class MyTry
    {
        static void Main(string[] args)
        {
          


            string[] lines = System.IO.File.ReadAllLines(@"C:\c_temp\test\lines.txt");
            foreach (string line in lines)
            {
                               string[] columns = Regex.Split(line, "\\s+");
                Console.WriteLine(columns[0]);
            }

          }
    }
}

Open in new window

0
 
for_yanCommented:
this is of courese output form the above (that is exactly the gibberuish I tyoes in the fiorst columns of the file for testing):
sdfsd
sdf
sdfds

Open in new window

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now