Skip to content

Generate properly formatted and grammatically correct text lists from arrays and IEnumerables.

License

Notifications You must be signed in to change notification settings

neosmart/textlist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NeoSmart.TextList

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.

Options

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.

Output

  • [Meg] => Meg
  • [Meg, Jo] => Meg and Jo
  • [Meg, Jo, Beth] => Meg, Jo, and Beth
  • [Meg, Jo, Beth, Amy] => Meg, Jo, Beth, and Amy

Usage

The exact syntax for the usage of the TextList library depends on the implementation.

C#/.NET

//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"

C++

//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"

About

Generate properly formatted and grammatically correct text lists from arrays and IEnumerables.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published