Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从文本中获取URL_C#_Asp.net - Fatal编程技术网

C# 如何从文本中获取URL

C# 如何从文本中获取URL,c#,asp.net,C#,Asp.net,如何从文本中获取URL 例如: string Text = "this is text with url http://test.com"; 我必须获取url并将其设置为其他变量。如何使用ASP.NET实现这一点 reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; 这是从文本中查找URL的正则表达式 希望对您有所帮助。您可以使用 string _Url = "this is t

如何从文本中获取URL

例如:

string Text = "this is text with url http://test.com";
我必须获取url并将其设置为其他变量。如何使用ASP.NET实现这一点

reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
这是从文本中查找URL的正则表达式

希望对您有所帮助。

您可以使用

string _Url = "this is text with url http://test.com";

MatchCollection _Match = Regex.Matches(_Url , @"http.+)([\s]|$)");
string _Address= _Match[0].Value.ToString();
/http | https | ftp | ftps\://[a-zA-Z0-9-.]+[a-zA-Z]{2,3}/\S*/

作为搜索的正则表达式。。。
;

String.Split方法字符串[],StringSplitOptions

<>你可以找到例子:C-C++ +F-VB

[ComVisibleAttributefalse] 公共字符串[]拆分 字符串[]分隔符, StringSplitOptions选项


在这种情况下,http://可以用作分隔符。

添加到前面的答案中,您也可以这样做:

string text = "this is text with url http://test.com";
Match match = Regex.Match(text, @"http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$");

// gets you http://test.com
string url = match.Value;
接下来做一点研究
string url = Text.Substring(Text.IndexOf("http://"));