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.
Nullableis enabled from 1.6.x.
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 fishA 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>intmain()
{
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(constdouble& d : _list)
std::cout<<d<<"";
std::cout<<_str;
// Output endreturn0;
}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:
usingSystem;usingSystem.Collections.Generic;usingSystem.Globalization;usingSystem.IO;usingFileParser;namespaceFileParserSample{classProgram{staticvoidMain(string[]args){varcultureInfo=newCultureInfo("en-US");CultureInfo.DefaultThreadCurrentCulture=cultureInfo;List<double>listDouble=newList<double>();stringstr;// Input startIParsedFilefile=newParsedFile("SimpleInput.txt");IParsedLinefirstLine=file.NextLine();int_integer=firstLine.NextElement<int>();for(inti=0;i<_integer;++i)listDouble.Add(firstLine.NextElement<double>());str=firstLine.NextElement<string>();// Input end// Data Processing// Output startStreamWriterwriter=newStreamWriter("..\\CSharpSimpleOutput.txt");using(writer){writer.WriteLine(_integer+" "+string.Join(null,listDouble));}// Output end}}}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:
If anyone else ever happens to use FileParser, I'll be happy to accept suggestions and solve any doubts.
Just open an issue :)