NeoSmart.TextList
is an implementation of a plain-text, formatted list generator in multiple languages. Plain-text lists generated by TextList
are grammatically correct and efficiently generated, with options to customize the output.
The C#/.NET implementation of TextList
is available on NuGet. All code is licensed fully free under the MIT open source license. Contributions for TextList
implementations in different languages are welcomed and encouraged.
The TextList
library provides options to create a list either with or without the oxford comma (obviously defaulting to with rather than the without), and allow for the specification of the terminating conjunction (e.g. and
vs or
) and the list separator character/string (defaulting to ,
). TextList
generates correct, valid text sequences for any number of elements, from 1 onwards.
[Meg] => Meg
[Meg, Jo] => Meg and Jo
[Meg, Jo, Beth] => Meg, Jo, and Beth
[Meg, Jo, Beth, Amy] => Meg, Jo, Beth, and Amy
The exact syntax for the usage of the TextList
library depends on the implementation.
//using static NeoSmart.TextList;
var names = new [] {"Meg", "Jo", "Beth", "Amy"};
names.ToTextList(); //generates "Meg, Jo, Beth, and Amy"
names.ToTextList("or", ListFormatting.None); //generates "Meg, Jo, Beth or Amy"
//using namespace NeoSmart
auto names = std::vector<std::string>{ "Meg", "Jo", "Beth", "Amy" };
TextList::Make(names); //Generates "Meg, Jo, Beth, and Amy"
TextList::Make(names, "or", TextList::ListFormatting::None); //Generates "Meg, Jo, Beth or Amy"