试图在同一行的文档中搜索两个字符串

Trying to search two strings in a document in the same line

            WebClient wb = new WebClient();
            string License = wb.DownloadString("DocumentSite");
            if (License.Contains(LK.Text + UN.Text))

我想逐行搜索而不是整个文档

您可以使用 StringReader 逐行遍历字符串。

private async Task ReadLicenseAsync(string license)
{
  using var textReader = new StringReader(license);
  string line = string.Empty;
  while ((line = await textReader.ReadLineAsync()) != null)
  {
    // TODO::Handle line
  }
}

您实际上可以为此使用正则表达式。对每个字符串(以任意数量的字符为前缀)并锚定到行首的正向前瞻就足够了

var regex = "^" + string.Concat(new[]{LK.Text, UN.Text}.Select(s => $"(?=.*?{s})"));
if (Regex.Match(licence, regex, RegexOptions.Multiline))
{
....