Here is some code that reads Active Directory to get a person's manager and parses the result for the managers name. It omits the remaining information. I was just wondering if there might be some more efficient way of doing this instead of the code I am currently using.
var Manager = (string)UserDirectoryData.Properties["manager"].Value; var StartIndex = Manager.IndexOf("="); var EndIndex = Manager.IndexOf(","); StartIndex++; EndIndex--; var Length = EndIndex - StartIndex; Manager = Manager.Substring(StartIndex, Length);
The string returned in the first line of code is in this format:
The goal is to just get the name and drop the rest. As the Name length will vary and my RegEX is rusty I could not come up with a working RegEX for this or any other way in C# to pull the name.
Buy more efficient I mean faster run times and less resource utilization. This same code will be used in multiple spots in loops of up to 500 iterations (and it will continue to grow as the company does).