akd
akd

Reputation: 6730

What is the best way of separating ldap connection string?

I am trying to figure out the best way of getting domain name and the rest of the information into 2 strings by using regex or maybe an exsiting String method available from LDAP string.

Here is the active directory connection string:

"LDAP://yourdomain.com/OU=Bla,OU=Bla2,OU=Bla3,DC=yourdomain,DC=com"

and the out put I would like to get is:

string DomainName = "yourdomain.com"
string Container = "OU=Bla,OU=Bla2,OU=Bla3,DC=yourdomain,DC=com"

Upvotes: 1

Views: 1524

Answers (2)

Brian Agnew
Brian Agnew

Reputation: 272347

It's a standard URL (with protocol LDAP) and I would use the appropriate URL parsing/objects available to you.

var uri = new Uri(LDAPConnectionString);
var host = uri.Host;
var Container = uri.Segments[1];

etc.

Upvotes: 4

James
James

Reputation: 82136

This can be done using simple string manipulation (no need for a Regex).

var parts = "LDAP://yourdomain.com/OU=Bla,OU=Bla2,OU=Bla3,DC=yourdomain,DC=com".Replace("LDAP://", "").Split('/');
Console.WriteLine(parts[0]); // yourdomain.com
Console.WriteLine(parts[1]); // OU=Bla,OU=Bla2,OU=Bla3,DC=yourdomain,DC=com

Upvotes: 2

Related Questions