0

您好,我正在尝试为 windows phone 创建一个小 webapp。它拉下一个网页并将源代码保存在一个文本块中,我想要做的是让应用程序读取该文本块并确定其中是否包含一个设置值 =“ 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));
        }` 

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

4

2 回答 2

0

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

C# 的正则表达式备忘单

Regex Hero一个测试你的正则表达式的好地方

正则表达式匹配如何从 C# 中的正则表达式中获取匹配的值(你的问题)

编辑

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

于 2013-06-20T15:07:58.157 回答
0

这将尝试获取 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);
于 2013-06-20T15:13:00.397 回答