This is a great place to use Regular Expressions. Try this:
var text = "CN=Andrew Adams,OU=Services,OU=Users,OU=GIE,OU=CSP,OU=STAFF,DC=example,DC=net";
var match = Regex.Match(text, @"CN=([^,]+)");
if (match.Success) return match.Groups[0].Value;
The expression CN=([^,]+)
will look for the text CN=
followed by one or more non-commas, and will stick that part of it into Groups[0]
.