开发者

Manipulate an LDAP string

开发者 https://www.devze.com 2023-02-22 05:12 出处:网络
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.

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));
0

精彩评论

暂无评论...
验证码 换一张
取 消