如何在字符串中找到两个引号

Tom*_*röm 3 c# string parsing quotation-marks

我试图搜索一个文件,看看是否有任何行包含单词Description1并且如果在该特定行的某处有两个引号直接出现在彼此之后。

我找到了各种删除或替换它们的方法,但我想保留它们。

foreach (var line in File.ReadLines(FileName))
   {
    if (line.Contains ("Description1") )
       {
        MessageBox.Show ("Description1 found");

           if (line.Contains (@"""") )
              {                                                 
               MessageBox.Show ("ERROR! Empty Description1 found.");
              }
        }
}
Run Code Online (Sandbox Code Playgroud)

搜索的文件与此类似

 propertyDescriptor="22004" PropertyName="Description1" PropertyType="Part" PropertyValue="Cat"   
 propertyDescriptor="22004" PropertyName="Description1" PropertyType="Part" PropertyValue=""   
 propertyDescriptor="22006" PropertyName="Description2" PropertyType="Part" PropertyValue=""   

错误检查应该只检测第二行中的错误,其中描述 1 和两个引号都存在。

我的问题是我在文本 Description1 的每个实例上都收到错误消息。

有什么好主意吗?

提前致谢。

Tom*_*ada 6

使用line.Contains("\"\"")代替line.Contains(@"""")asline.Contains(@"""")将搜索“not”。

替换为您的代码:

foreach (var line in File.ReadLines(FileName))
{
    if (line.Contains ("Description1") )
    {
        MessageBox.Show ("Description1 found");

        if (line.Contains ("\"\"") )
        {                                                 
            MessageBox.Show ("ERROR! Empty Description1 found.");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)