Search code examples
delphidelphi-7

Recommendations to read and parse an Fixed Width Text File using Delphi


Which is the best way to read and parse an Fixed Width Text File using Delphi?

Does any component exist for that?


Solution

  • If by read you mean parse, try using a TStringList. Call TStringList.LoadFromFile and you'll get a list of individual lines. Then you can go over each individual line and parse it out into a record or class based on the various fixed-length columns in the line. Check out the Copy function for a way to make this easier.

    It's hard to be more specific without any details about what you're trying to do, but that's the general idea.