查找字符串是否包含值,然后提取

本文关键字:然后 提取 包含值 字符串 是否 查找 | 更新日期: 2023-09-27 18:19:26

你好,我正在尝试为windowsphone创建一个小的网络应用程序。它下拉一个微信页面,并将源代码保存在一个文本块中,我想做的是让应用程序读取该文本块,并确定中是否包含一个设置值="http://test.com"如果是,我希望它提取完整的网址。

到目前为止,我有

        string stringToCheck = "http://test.com";
        string stringhtml = invisiBlockHtml.Text;
        if (stringhtml.Contains(stringToCheck))
        {
            // StreamReader sr = new StreamReader(stringhtml);
            // here i was hoping there was some way for StreamReader or another function to read the string and then pull out the full url

        webBrowser1.Navigate(new Uri("found Url", UriKind.Absolute));  }
        else
        {
            webBrowser1.Navigate(new Uri("http://dontcontain.com", UriKind.Absolute));
        }` 

希望这是有道理的,我最近才开始编程。感谢

查找字符串是否包含值,然后提取

这将尝试获得与匹配的url

string mystring = "My text and url http://www.google.com and some more text.";
Regex urlRx = new Regex(@"(?<url>(http:[/][/]|www.)([a-z]|[A-Z]|[0-9]|[/.]|[~])*)", RegexOptions.IgnoreCase);
MatchCollection matches = urlRx.Matches(mystring);

我发表了评论,但这里有一个完整的正则表达式指南->

C#的Regex备忘单

Regex Hero测试您的Regx 的好地方

Regex匹配如何在C#中从Regex中取回匹配的值(您的问题)

编辑

虽然我可能误解了这个问题。你是在寻找一个确切的网址,还是任何网址?如果您正在寻找一个精确的URl,那么如果.Contains()返回true,则您已经知道URl