簡體   English   中英

通過正則表達式查找字符串中的鏈接

[英]Find link in a string by regex

所以我有一個像這樣的字符串

 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"};

我這樣做,因為我想重建字符串,但使用鏈接的其他東西。

使用string.Split方法:

string[] chopped = org.Split(' ');

它返回string數組而不是List<string>

但你還是得照顧像人物, 您可以嘗試執行以下操作:

string []chopped = org.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

它將使用空格和逗號分割並返回忽略空的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM