我正在遍历一个字符串列表,以查看该字符串是否包含在字典的值中,然后尝试从该值中删除该字符串。
目前我是这样做的:
对我来说,这似乎有点冗长。有没有更好的方法来做到这一点?
目前我是这样做的:
Dictionary<String, String> formValues = new Dictionary<String, String>();
formValues["key1"] = "the something at";
formValues["key2"] = "the something on";
formValues["key3"] = "the something is";
string prepositionList = "at,as,if,of,the,to,a,an,it,is,by,its";
List<string> prepositionListValues = new List<string>(prepositionList.Split(','));
foreach (string preposition in prepositionListValues)
{
List<string> keys = new List<string>(formValues.Keys);
foreach (string key in keys)
{
if (formValues[key] != null)
{
if (formValues[key].Contains(preposition))
{
formValues[key] = formValues[key].Replace(preposition, "");
}
}
}
}
对我来说,这似乎有点冗长。有没有更好的方法来做到这一点?