我有一个字符串表,例如:
string[] list = { "900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org" };
string delimiter = ".";
foreach (var item in cpdomains)
{
var result = item.Split(' ', '.').Aggregate((a,b) => a + delimiter +b);
result.ForEach(e => Console.WriteLine(e));
Console.WriteLine(result);
}
我现在的结果
我想将每个字符串分成这样的子字符串:
1- 900
2- google.mail.com
3-mail.com
4-com
etc...
我该怎么做? 预先感谢
答案 0 :(得分:0)
public string[] GetParentDomains(string[] input) {
return input
.SelectMany(s => s.Split(' '))
.SelectMany(s => {
string[] splitDomain = s.Split('.');
return Enumerable.Range(0, splitDomain.Length)
.Select(counter =>
String.Join(".", splitDomain.Skip(counter)))
.ToArray();
})
.ToArray();
}
输出
900
google.mail.com
mail.com
com
50
yahoo.com
com
1
intel.mail.com
mail.com
com
5
wiki.org
org