We help IT Professionals succeed at work.

VS 2008 C# Text File Import

rwheeler23
rwheeler23 asked
on
Medium Priority
243 Views
Last Modified: 2013-12-16
I am being sent a pipe delimited text file with about 100 fields in it. I only care about 8 of them. How  do I set up the VS C# program to read this text file and then extract only the 8 values that I need? What kind of text reader do I use and how do I set up the extractions?
Comment
Watch Question

djon2003Senior software engineer
CERTIFIED EXPERT

Commented:
Can you show us a simple version of your file ?
rwheeler23President

Author

Commented:
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
What kind of text reader do I use and how do I set up the extractions?
The VB guys wrote a CSV parser which you are free to use (since you are working in .NET land). I posted an example here:  http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_26703218.html#34431727

string path = @"c:\poc\csv.txt";
            string content = File.ReadAllText(path);
            
            IEnumerable<string> Values = content.Split("|".ToCharArray()).Where<string>( s => s != string.Empty);
            List<string> seperatedList = new List<string>();
            foreach (string s in Values)
            {
                seperatedList.Add(s);
                Console.WriteLine(s);
            }


            //Loop through the list seperatedList and take the values you want!

Open in new window

Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016
Commented:
rwheeler23President

Author

Commented:
Thanks for all the help!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.