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)?
11 Answers
You also have the System.Data.Entity.Design.PluralizationServices.PluralizationService.
UPDATE: Old answer deserves update. There's now also Humanizer: https://github.com/MehdiK/Humanizer

- 26,990
- 7
- 84
- 140

- 8,133
- 5
- 36
- 51
-
2Hmmm are you allow to redistribute, or just use, a Design DLL? I ask that because I know that the license for DevExpress prohibit redistributing any .design DLL. – Pierre-Alain Vigeant Mar 30 '11 at 19:39
-
63Opening the code with ILSpy shows a class called EnglishPluralizationService, which has lots of exceptional cases defined in and makes for interesting reading. I particularly like 'pneumonoultramicroscopicsilicovolcanoconiosis', which I find myself using all the time in my entity models... 8o) – MrKWatkins Jan 19 '12 at 17:41
-
8I can guess how that got added. A tester filed a bug on the dev saying it does not work for the said word. Dev fixed it. Both shared a laugh. – merlinbeard Mar 30 '13 at 15:43
-
2@MrKWatkins Sounds more like 'supercalifragilisticexpialidocious' – Corstian Boerman Apr 01 '15 at 11:58
-
1Humanizer is a great recommendation. I'd of course implemented like 15% of it myself before finding out it existed. – Casey May 06 '15 at 14:44
-
PluralizationService fails on "Courses". It singularizes to "Cours". – Morgan Thrapp Nov 11 '16 at 21:27
I can do it for Esperanto, with no special cases!
string plural(string noun) { return noun + "j"; }
For English, it would be useful to become familiar with the rules for Regular Plurals of Nouns, as well as Irregular Plurals of Nouns. There is a whole Wikipedia article on the English plural, which may have some helpful information too.

- 951,095
- 183
- 1,149
- 1,285
-
5
-
1@Matt: Of course this is appropriate for the nominative case; I trust that extending this method to the accusative case is straightforward for an astute reader. – Greg Hewgill Jul 27 '12 at 02:36
Most ORMs have a stab at it, although they generally aren't perfect. I know Castle has it's Inflector Class you can probably poke around. Doing it "perfectly" isn't an easy task though (English "rules" aren't really rules :)), so it depends if you are happy with a "reasonable guess" approach.

- 160,644
- 26
- 247
- 397

- 26,441
- 7
- 76
- 90
-
From your suggestion I searched for "Inflector" and found this http://andrewpeters.net/inflectornet/ that sould basically be the same of the Castle one – Ronnie Jan 24 '09 at 08:02
-
4
I cheated in Java - I wanted to be able to produce a correct string for "There were n something(s)", so I wrote the foll. little overloaded utility method:
static public String pluralize(int val, String sng) {
return pluralize(val,sng,(sng+"s"));
}
static public String pluralize(int val, String sng, String plu) {
return (val+" "+(val==1 ? sng : plu));
}
invoked like so
System.out.println("There were "+pluralize(count,"something"));
System.out.println("You have broken "+pluralize(count,"knife","knives"));

- 63,018
- 25
- 139
- 189
-
This only covers a small sections of grammar though, it doesn't account for words like quizzes, parties, halves, mice, indices, etc. It's a good first stab, but there are a lot of other rules that should probably be processed first. – Jeremy S Jan 12 '10 at 19:23
-
4@Jeremy: Why not?: println("You have passed " + singularPlural(count,"quiz","quizzes") + " so far") – Lawrence Dol Jan 27 '10 at 02:22
-
I might be interpreting the question differently. I'm thinking the algorithm should be determining the plural form without any hint from the developer, while your method puts the onus of knowing what the plural form is on the developer. – Jeremy S Jan 27 '10 at 17:09
-
3@Jeremy: Hence the "I cheated..." lead in - doesn't seem to warrant a downvote. – Lawrence Dol Sep 17 '10 at 04:34
-
1Agreed. I also think the information provided was useful, which is why any downvote didn't come from me. I don't downvote in general, along the lines of the "one man's junk...". – Jeremy S Oct 20 '10 at 16:29
-
Just wait till you have to localize this into different languages. I would rather avoid the problem and do `Number of something: n` – Kugel Jan 30 '14 at 23:54
-
@Kugel: Been there done that, and this method is not relevant for NLS support, only for a very simple *possible* solution to the question posed by the OP (which specifically restricted things to English). – Lawrence Dol Jan 31 '14 at 00:51
-
I had to read this several times to realize what the parameter names were meant to be and thus what the method actually does. Characters are free. Naming the parameters `singular` and `plural` would have made the method 100X more clear. – MgSam Feb 02 '22 at 21:16
-
@MgSam : Characters might be free, but my time is not -- please don't waste it by making comments about debatable matters of style. – Lawrence Dol Feb 03 '22 at 22:30
I've created a tiny library for this in .net (C#), called Pluralizer (unsurprisingly).
It's meant to work with full sentences, something like String.Format does.
It basically works like this:
var target = new Pluralizer();
var str = "There {is} {_} {person}.";
var single = target.Pluralize(str, 1);
Assert.AreEqual("There is 1 person.", single);
// Or use the singleton if you're feeling dirty:
var several = Pluralizer.Instance.Pluralize(str, 47);
Assert.AreEqual("There are 47 people.", several);
It can also do way more than that. Read more about it on my blog. It's also available in NuGet.

- 1,257
- 1
- 12
- 15
-
Any advantage over [System.Data.Entity.Design.PluralizationServices.PluralizationService](http://msdn.microsoft.com/en-us/library/system.data.entity.design.pluralizationservices.pluralizationservice.aspx)? – John Saunders Mar 04 '11 at 01:58
-
4Yup, that library only does single words, and only nouns (although Pluralizer uses that class internally). This library makes to make whole sentences easier to write. Have a look at my blog for more examples. Pluralizer.Instance.Pluralize("{She} {is} going to {her|their respective} {home}.", 5) – Jay Querido Mar 04 '11 at 02:28
-
Shaun Wilson - My computer is currently in parts. I'm rushing to get it back up and will update within a day or two. In the mean time, http://nuget.org/packages?q=pluralizer – Jay Querido Jan 30 '13 at 22:34
I whipped one together based on the Rails pluralizer. You can see my blog post here, or on github here
output = Formatting.Pluralization(100, "sausage");

- 11,964
- 6
- 62
- 89
-
3Thanks for sharing. Glad I didn't need to reference another assembly. – hofnarwillie Sep 29 '14 at 12:34
-
1
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"

- 13,225
- 9
- 67
- 88
Subsonic 3 has an Inflector
class which impressed me by turning Person
into People
. I peeked at the source and found it naturally cheats a little with a hardcoded list but that's really the only way of doing it in English and how humans do it - we remember the singular and plural of each word and don't just apply a rule. As there's not masculine/feminine(/neutral) to add to the mix it's a lot simpler.
Here's a snippet:
AddSingularRule("^(ox)en", "$1");
AddSingularRule("(vert|ind)ices$", "$1ex");
AddSingularRule("(matr)ices$", "$1ix");
AddSingularRule("(quiz)zes$", "$1");
AddIrregularRule("person", "people");
AddIrregularRule("man", "men");
AddIrregularRule("child", "children");
AddIrregularRule("sex", "sexes");
AddIrregularRule("tax", "taxes");
AddIrregularRule("move", "moves");
AddUnknownCountRule("equipment");
It accounts for some words not having plural equivalents, like the equipment example. As you can probably tell it does a simple Regex
replace using $1.
Update:
It appears Subsonic's Inflector
is infact the Castle ActiveRecord Inflector
class!

- 64,770
- 52
- 221
- 239
Not much documentation from MSDN on the specific usage of the PluralizationService class so here is a unit test class (NUnit) to show basic usage. Notice the odd test case at the bottom that shows the service isn't perfect when it comes to non-standard plural forms.
[TestFixture]
public class PluralizationServiceTests
{
[Test]
public void Test01()
{
var service = PluralizationService.CreateService(CultureInfo.CurrentCulture);
Assert.AreEqual("tigers", service.Pluralize("tiger"));
Assert.AreEqual("processes", service.Pluralize("process"));
Assert.AreEqual("fungi", service.Pluralize("fungus"));
Assert.AreNotEqual("syllabi", service.Pluralize("syllabus")); // wrong pluralization
}
}

- 5,548
- 12
- 44
- 54
Using Microsoft's Northwind example database:
System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(new System.Globalization.CultureInfo("en-US"));
Singularize does not Singularize "Order_Details"
It returns "Order_Details" with the s
at the end. What is the work around?
-
2This is a question, not an answer to a question... but Pluralize() and Singularize() only work with dictionary words. There's a way to add words using ICustomPluralizationMapping.AddWord, but at least for me that wasn't a very good solution when you may have lots of not-real words like code names. – tordal Feb 19 '15 at 18:22
-
You can use PluralizationService
of System.Data.Entity
(.NET Framework 4.0), as shown in this page:
http://zquanghoangz.blogspot.it/2012/02/beginner-with-pluralizationservices.html