Is there any algorithm in c# to singularize - pluralize a word (in english) or does exist a .net library to do this (may be also in different languages)?
As the question was for C#, here is a nice variation on Software Monkey's solution (again a bit of a "cheat", but for me really the most practical and reusable way of doing this):
public static string Pluralize(this string singularForm, int howMany)
{
return singularForm.Pluralize(howMany, singularForm + "s");
}
public static string Pluralize(this string singularForm, int howMany, string pluralForm)
{
return howMany == 1 ? singularForm : pluralForm;
}
The usage is as follows:
"Item".Pluralize(1) = "Item"
"Item".Pluralize(2) = "Items"
"Person".Pluralize(1, "People") = "Person"
"Person".Pluralize(2, "People") = "People"