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;
}
暂时没想到更简洁的方法