zoukankan      html  css  js  c++  java
  • ahjesus 单词单数-复数相互转换C#

    public static class StringUtil
        {
            /// <summary>
            /// 单词变成单数形式
            /// </summary>
            /// <param name="word"></param>
            /// <returns></returns>
            public static string ToSingular(string word)
            {
                Regex plural1 = new Regex("(?<keep>[^aeiou])ies$");
                Regex plural2 = new Regex("(?<keep>[aeiou]y)s$");
                Regex plural3 = new Regex("(?<keep>[sxzh])es$");
                Regex plural4 = new Regex("(?<keep>[^sxzhyu])s$");
    
                if (plural1.IsMatch(word))
                    return plural1.Replace(word, "${keep}y");
                else if (plural2.IsMatch(word))
                    return plural2.Replace(word, "${keep}");
                else if (plural3.IsMatch(word))
                    return plural3.Replace(word, "${keep}");
                else if (plural4.IsMatch(word))
                    return plural4.Replace(word, "${keep}");
    
                return word;
            }
            /// <summary>
            /// 单词变成复数形式
            /// </summary>
            /// <param name="word"></param>
            /// <returns></returns>
            public static string ToPlural(string word)
            {
                Regex plural1 = new Regex("(?<keep>[^aeiou])y$");
                Regex plural2 = new Regex("(?<keep>[aeiou]y)$");
                Regex plural3 = new Regex("(?<keep>[sxzh])$");
                Regex plural4 = new Regex("(?<keep>[^sxzhy])$");
    
                if (plural1.IsMatch(word))
                    return plural1.Replace(word, "${keep}ies");
                else if (plural2.IsMatch(word))
                    return plural2.Replace(word, "${keep}s");
                else if (plural3.IsMatch(word))
                    return plural3.Replace(word, "${keep}es");
                else if (plural4.IsMatch(word))
                    return plural4.Replace(word, "${keep}s");
    
                return word;
            }
        }
  • 相关阅读:
    20201130-栈与链表
    K-means算法
    支持向量机-SVC
    贝叶斯-实现新闻数据分类
    贝叶斯-使用贝叶斯实现拼写检查器
    泰坦尼克求胜率预测-基于随机森林实现
    决策树算法-Python实现
    SQL_牛客网60题
    信用卡欺诈模型-逻辑回归
    用python实习逻辑回归
  • 原文地址:https://www.cnblogs.com/nele/p/5287169.html
Copyright © 2011-2022 走看看