Ano*_*urn 1 c# foreach combobox loops
我需要将组合框的每个项目与字符串的单词进行比较.如果它匹配,我需要在字符串的单词前面加上一个$.
我尝试过
if (!String.IsNullOrEmpty(modify))
{
foreach(string item in tcomboBox1.Items)
{
bool contains = Regex.IsMatch(modify, @"\b"+item+"\b");
if (contains == true)
{
string theItem = "$" + item + "$";
modify = modify.Replace(item,theItem);
}
}
ttextBox1.Text = modify;
modify = "";
}
Run Code Online (Sandbox Code Playgroud)
但是没有追加$符号.为什么?
编辑
你的代码是正确的,根据给定的输入和结果问题的例子在你的正则表达式中,似乎你不需要"\b"尝试:
bool contains = Regex.IsMatch(modify,item);
Run Code Online (Sandbox Code Playgroud)