コード例 #1
0
        private string ToPlural(string str)
        {
            var word    = GetLastWord(str);
            var newWord = Plurals.ToPlural(word);

            if (word != newWord)
            {
                if (char.IsUpper(word[0]))
                {
                    newWord = char.ToUpper(newWord[0]) + newWord.Substring(1, newWord.Length - 1);
                }

                return(word == str ? newWord : str.Substring(0, str.Length - word.Length) + newWord);
            }

            return(str);
        }
コード例 #2
0
        private string ToSingular(string str)
        {
            if (str.ToLowerInvariant().EndsWith("ess"))
            {
                return(str);
            }

            var word    = GetLastWord(str);
            var newWord = Plurals.ToSingular(word);

            if (word != newWord)
            {
                if (char.IsUpper(word[0]))
                {
                    newWord = char.ToUpper(newWord[0]) + newWord.Substring(1, newWord.Length - 1);
                }

                return(word == str ? newWord : str.Substring(0, str.Length - word.Length) + newWord);
            }

            return(str);
        }