ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

ToPlural

Returns the plural of a word.

Source

public static string ToPlural(this string singular)
{
    // Multiple words in the form A of B : Apply the plural to the first word only (A)
    int index = singular.LastIndexOf(" of ");
    if (index > 0) return (singular.Substring(0, index)) + singular.Remove(0, index).ToPlural();

    // single Word rules
    //sibilant ending rule
    if (singular.EndsWith("sh")) return singular + "es";
    if (singular.EndsWith("ch")) return singular + "es";
    if (singular.EndsWith("us")) return singular + "es";
    if (singular.EndsWith("ss")) return singular + "es";
    //-ies rule
    if (singular.EndsWith("y")) return singular.Remove(singular.Length - 1, 1) + "ies";
    // -oes rule
    if (singular.EndsWith("o")) return singular.Remove(singular.Length - 1, 1) + "oes";
    // -s suffix rule
    return singular + "s";
}

Example

string person = "person";
string personPlural = person.ToPlural;

Author: Marco de Brouwer

Submitted on: 11 jul. 2008

Language: C#

Type: System.String

Views: 6291