I need to split a List connection below on the basis of value equals after cn= ex.Group Policy,Users,Administrators,Enterprise Admins in a new List which contains the unique values seen below expected value in c#
[0] "cn=Group Policy,cn=Users,dc=ldapdomain,dc=domain"
[1] "cn=Administors,cn=Users,dc=ldapdomain,dc=domain"
[2] "cn=Enterprise Admins,cn=LogUsers,dc=ldapdomain,dc=domain"
My expected scenario is to get a List with value below
cn[0]="Group Policy";
cn[1]="Users";
cn[2]="Administrators";
cn[3]="Enterprise Admins";
cn[4]="LogUsers";
I am trying with below code but not finding a way to split cn=
List<string> connection = new List<string>();
List<string> groups = new List<string>();
groups.Add("cn=Group Policy,cn=Users,dc=ldapdomain,dc=domain");
groups.Add("cn=Administors,cn=Users,dc=ldapdomain,dc=domain");
groups.Add("cn=Enterprise Admins,cn=LogUsers,dc=ldapdomain,dc=domain");
foreach(var group in groups)
{
group.Split("cn=");
}
var list = groups
.SelectMany(g => g.Split(',')) // split each into an array and select each item
.Where(cn => cn.StartsWith("cn=", StringComparison.OrdinalIgnoreCase))
.Select(cn => cn.Substring(3)) // cut off the first 3 characters
.Distinct(StringComparison.OrdinalIgnoreCase) // only distinct items
.ToArray();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.