2013-10-24 593 views
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"}; 

我這樣做是因爲我想重建字符串,但使用鏈接別的東西。

回答

3

使用string.Split方法:

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

它返回string代替List<string>陣列。

但是你仍然需要照顧像,這樣的字符。您可以嘗試執行以下操作:

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

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