gpt4 book ai didi

c# - 如何查看一个字符串是否包含另一个带引号的字符串?

转载 作者:太空宇宙 更新时间:2023-11-03 22:54:52 25 4
gpt4 key购买 nike

我正在尝试查看一个大字符串是否包含这行 HTML:

<label ng-class="choiceCaptionClass" class="ng-binding choice-caption">Was this information helpful?</label>

如您所见,此代码段在多个位置引用,当我执行以下操作时会导致问题:

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 字符串没有。

关于c# - 如何查看一个字符串是否包含另一个带引号的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45868395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com