Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.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# 通过正则表达式查找字符串中的链接_C#_Regex_String_Windows 8_Windows 8.1 - Fatal编程技术网

C# 通过正则表达式查找字符串中的链接

C# 通过正则表达式查找字符串中的链接,c#,regex,string,windows-8,windows-8.1,C#,Regex,String,Windows 8,Windows 8.1,我有一根这样的绳子 String org = "Go to http://Apple.com, to see the new Ipad"; 如何返回包括url在内的字符串中所有单词的列表? 例如上面的字符串应返回此列表 List<String> chopped = new List<String>(){"Go", "to", "http://Apple.com", " to", "see" , " the", " new", " Ipad"}; List-sho

我有一根这样的绳子

 String org = "Go to http://Apple.com, to see the new Ipad";
如何返回包括url在内的字符串中所有单词的列表? 例如上面的字符串应返回此列表

List<String> chopped = new List<String>(){"Go", "to", "http://Apple.com",  " to", "see" , " the", "  new", " Ipad"};
List-shopped=new-List(){“Go”,“to”,“to”http://Apple.com“,”to“,”see“,”the“,”new“,”Ipad“};

我这样做是因为我想重建字符串,但将链接用于其他内容。

使用
string.Split
方法:

string[] chopped = org.Split(' ');
它返回
字符串的数组
,而不是
列表

但是您仍然需要处理像
这样的字符。您可以尝试执行以下操作:

string []chopped = org.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
它将使用空格和逗号进行拆分,并返回忽略空结果的结果