Manipulate an LDAP string
I have an LDAP path and I only want the OU's from it. How can I manipulate it to get the OU's??
e.g.
LDAP://company.com/OU=MyOU,DC=MyCompany,DC=com
to be show as MyOU
LDAP://company.com/OU=MyOU1,OU=MyOU2,DC=MyCo开发者_StackOverflowmpany,DC=com
to be shown as MyOU1/MyOU2
LDAP://company.com/OU=MyOU1,OU=MyOU2,OU=MyOU3,DC=MyCompany,DC=com
to be shown as MyOU1/MyOU2/MyOU3
Any suggestions? Thanks
This should work
string str = "LDAP://company.com/OU=MyOU1,OU=MyOU2,OU=MyOU3,DC=MyCompany,DC=com";
Regex regex = new Regex("OU=\\w+");
var result = regex.Matches(str);
var strList = new List<string>();
foreach (var item in result)
{
strList.Add(item.ToString().Remove(0,3));
}
Console.WriteLine(string.Join("/",strList));
精彩评论