FileParser 3.0.0

dotnet add package FileParser --version 3.0.0                
NuGet\Install-Package FileParser -Version 3.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FileParser" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FileParser --version 3.0.0                
#r "nuget: FileParser, 3.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FileParser as a Cake Addin
#addin nuget:?package=FileParser&version=3.0.0

// Install FileParser as a Cake Tool
#tool nuget:?package=FileParser&version=3.0.0                

FileParser

Azure DevOps GitHub Actions Circle CI

Sonar Quality Code coverage Sonar vulnerabilities Sonar bugs Sonar code smells

Nuget

API

FileParser is a .NET library designed to read text files line-by-line, saving each line's content into basic types vars (int, double, string, etc.).

  • .NET Framework 4.6 was supported until v1.4.x.
  • .NET Standard 2.0 and 2.1 were supported until v1.6.x.
  • Nullable is enabled from 1.6.x.

Purpose

This project was born with a very specific purpose: providing a tool with whom easily parse files with a known structure, ideally being as flexible and easy to use as C++ standard IO approach.

For those who don't understand what I mean, here's a simple Use Case (also reposited):

Given the following input.txt, which contains an integer n (>=0) followed by n doubles and a final string,

5   1.1 3.14159265 2.2265       5.5 10              fish

A simple .cpp snippet like the following one could process input.txt, providing that file is selected as standard input source:

./myExecutable < input.txt > output.txt

#include <iostream>
#include <list>
#include <string>

int main()
{
    int _integer;
    std::string _str;
    std::list<double> _list;
    double _auxdouble;

    // Input start;
    std::cin>>_integer;
    for(int i=0; i<_integer; ++i)
    {
        std::cin>>_auxdouble;
        _list.push_back(_auxdouble);
    }
    std::cin>>_str;
    // Input end

    // Data processing

    // Output start
    std::cout<<_integer<<" ";
    for(const double& d : _list)
        std::cout<<d<<" ";
    std::cout<<_str;
    // Output end

    return 0;
}

Seems effortless to process these kind of simple .txt files using C++, right?

Well, using C# things are not so straight-forward, and that's why FileParser was created for:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;

using FileParser;

namespace FileParserSample
{
    class Program
    {
        static void Main(string[] args)
        {
            var cultureInfo = new CultureInfo("en-US");
            CultureInfo.DefaultThreadCurrentCulture = cultureInfo;

            List<double> listDouble = new List<double>();
            string str;

            // Input start
            IParsedFile file = new ParsedFile("SimpleInput.txt");
            IParsedLine firstLine = file.NextLine();

            int _integer = firstLine.NextElement<int>();

            for(int i=0; i<_integer; ++i)
                listDouble.Add(firstLine.NextElement<double>());

            str = firstLine.NextElement<string>();
            // Input end

            // Data Processing

            // Output start
            StreamWriter writer = new StreamWriter("..\\CSharpSimpleOutput.txt");
            using (writer)
            {
                writer.WriteLine(_integer + " " + string.Join(null, listDouble));
            }
            // Output end
        }
    }
}

Documentation

I've done my best to create a WIKI describing FileParser API.

Besides the WIKI, some real (own) projects where it has been used are:

Contributing, issues, suggestions, doubts

If anyone else ever happens to use FileParser, I'll be happy to accept suggestions and solve any doubts.

Just open an issue 😃

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 1,772 12/5/2023
3.0.0-alpha.1 660 12/2/2023
2.4.0 1,320 12/5/2022
2.3.0 407 12/2/2022
2.2.0 1,015 11/19/2021
2.1.1 1,817 12/6/2020
2.1.0 535 12/6/2020
2.0.0 612 11/10/2020
1.6.0 642 11/6/2020
1.5.0 671 5/19/2020
1.4.4 637 4/4/2020
1.4.3 615 3/1/2020
1.4.2 589 3/1/2020
1.4.1 589 3/1/2020
1.4.0 514 3/1/2020
1.3.1 650 12/3/2019
1.3.0 753 5/4/2019
1.2.0 788 12/25/2018
1.1.0 1,808 3/9/2018
1.0.0 1,034 3/7/2018
0.2.1 1,058 3/1/2018
0.2.0 1,038 2/28/2018
0.1.0 1,025 2/25/2018