• 替换掉字符串中重复的词(只保留一个)


                private string allKeywords = "";
            public string outputKeywords(Model.users users)
            {
                allKeywords += (" "+keywordsOfAge(users.age));
                allKeywords += (" " + keywordsOfSex(users.sex));
                allKeywords += (" " + keywordsOfHightAndWeight(users.hight, users.weight, users.sex));
                allKeywords += (" " + keywordsOfJob(users.job));
                allKeywords += (" " + keywordsOfyylx(users.yylx));
                string[] jj = keywordsOfjj(users.jj).Split(' ');
                for(int i =0;i<jj.Length;i++)
                {
                    allKeywords = allKeywords.Replace(jj[i],"");
                }

          

    //allKeywords中是有可能包含重复词的字符串,而且词之间以空格隔开

                allKeywords = Regex.Replace(allKeywords, "\\s+", " ");//替换掉词之间多余的空格(多于1个空格的替换成一个)

                //开始替换掉重复的关键字
                string[] allKeywords2 =allKeywords.Split(' ');
                ArrayList al = new ArrayList();
                for (int i = 0; i < allKeywords2.Length; i++)
                {
                    if (!al.Contains(allKeywords2[i]))
                    {
                        al.Add(allKeywords2[i]);
                    }
                }
                allKeywords = "";//清理原来的字符串
                for (int i = 0; i < al.Count; i++)
                {
                    allKeywords += al[i] + " ";
                }
                return allKeywords;
            }

    暂时没想到更简洁的方法

               

  • 相关阅读:
    根据系统的pid查询sql语句
    DORADO实现动态拼装查询条件
    一个Spring的配置管理接口
    MS SQL Server Management Studio连接到SQL Server命名实例的方法
    WSDL学习笔记
    显示MyBatis/Ibatis的SQL语句
    测试代码显示
    C#中一个项目中无法引用另外一个项目中的类的问题
    Learn How To Use LogMiner(Practice)
    WIN2003 IIS6 FastCGI php5.33配置重点
  • 原文地址:https://www.cnblogs.com/terrorpig/p/1350990.html
Copyright © 2020-2023  润新知