【发布时间】:2018-02-02 17:40:22
【问题描述】:
我正在尝试查看一个大字符串是否包含这行 HTML:
<label ng-class="choiceCaptionClass" class="ng-binding choice-caption">Was this information helpful?</label>
如您所见,这个 sn-p 在多个地方都有引号,当我执行以下操作时会导致问题:
Assert.IsTrue(responseContent.Contains("<label ng-class="choiceCaptionClass" class="ng - binding choice - caption">Was this information helpful?</label>"));
我已经尝试了这两种定义字符串的方法:
@"<label ng-class=""choiceCaptionClass"" class=""ng - binding choice - caption"">Was this information helpful?</label>"
和
"<label ng-class=\"choiceCaptionClass\" class=\"ng - binding choice - caption\">Was this information helpful?</label>"
但在每种情况下, Contains() 方法都会查找带有双引号或反斜杠的文字字符串。有没有另一种方法可以定义这个字符串,以便我可以正确搜索它?
【问题讨论】:
-
用正则表达式试试
-
不可以使用HTML Agility Pack 吗?它为您处理搜索/解析 HTML。这样你就不必自己动手了。
-
好主意,我忘记使用敏捷包了。我将把它包括在我接下来的工作中。