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);
它将使用空格和逗号进行拆分,并返回忽略空结果的结果