Alternatives for advanced reading and analysis of text files using .NET

I need to read from different text files (I have files with limited access and some files with a fixed width). I looked at parsing files line by line (slow using methods like File.ReadLine) and reading a file using an ODBC text driver (faster), but does anyone have any other (better) suggestions? I am using .NET / C #.

+3
source share
9 answers

Answering my own question:

I ended up using the Microsoft.VisualBasic.FileIO.TextFieldParser object, see

http://msdn.microsoft.com/en-us/library/f68t4563.aspx

(example implementation here)

csv, , , , , ..

+3

, Excel , Excel -//, . excel MS Office.

FileHelpers - , . , .

+5

Excel ( ):

, LINQ txt ( csv)

. , IEnumerable:

var records =                File.ReadAllLines(@ "c:\blah.txt" ). Skip (1)               let parts = line.Split('|')                ;

+3

, File. , :

  • ReadAllBytes
  • ReadAllLines
  • ReadAllText
+1

. , , .

,.NET (File.ReadAllLines). , , , .

Excel - ..XLS , , ..XLSX Excel 2007 XML-, XML, XML . XML, .

+1

,

: -

using System.IO;

...

public class Program {
  public static void Main() {
    foreach(string s in File.ReadAllLines(@"c:\foo\bar\something.txt") {
      // Do something with each line...
    }
  }
}
+1

, , File , . , , . File.ReadAllText( )

0

XLS:

Microsoft Office XP , .NET SDK Office, "" XLS, Word, PPT .. , Office XP ( ​​.NET).

, , Microsoft Office.

- ( Office 2007 -aka: Office 12) - COM-, , . I..: , Office XP (Office11), Office 12, , . "" . , Office 12 , - Office 11. .: S

I don’t know why Microsoft has never created the Microsoft.Office.XXXX (wrapper) managed library around these ugly things.

Anyway, your question is rather strange, try following the tips here. Good luck

0
source

The ODBC text driver is now deprecated - it does not support Unicode.

Surprisingly, MS Excel still uses it, so if you open Unicode CSV in Excel 2007 (and not import it), you lose all non-ASCII characters.

It is best to use .Net file reader methods like others.

0
source

Source: https://habr.com/ru/post/1696587/


All Articles