To Plural String - CSharp System

CSharp examples for System:String Format

Description

To Plural String

Demo Code



public class Main{
        public static string ToPlural(this string str)
        {// ww  w. ja va  2 s.c o m
            if (str.Equals("dois") || str.Equals("tr?s") || str.Equals("seis") || str.Equals("dez"))
                return str;

            if (str.Equals("existe"))
                return "existem";

            if (str == "tem")
                return "t?m";

            if (str.EndsWith("ol"))
                return str.Remove(str.Length - 2, 2) + "?is";

            if (str.EndsWith("z") || str.EndsWith("r") || str.Equals("canon"))
                return str + "es";

            if (str.EndsWith("?o"))
                return str.Remove(str.Length - 2, 2) + "?es";

            if (str.EndsWith("l"))
                return str.Remove(str.Length - 1, 1) + "is";

            if (str.EndsWith("?s"))
                return str.Remove(str.Length - 2, 2) + "eses";

            return str + "s";
        }
}

Related Tutorials