I'm looking for the most streamlined method to token a string like this into variables:
I want to place the values in their own variables. For example:
string fullName = "John Doe";
string ou = "Accounting";
How can I do this programmatically? Here is what I came up with, although it doesn't seem to be the most efficient way to do it. Something like this:
public static void Main (string args)
string test = "fullName=John Doe;ou=Accounting;firstname.lastname@example.org;telephoneNumber=123-4560;cn=JDoe";
string ou = GetField(test, "ou");
string mail = GetField(test, "mail");
string telephoneNumber = GetField(test, "telephoneNumber");
// and so on...
private static string GetField (string source, string var)
string delimiter = ";";
return source.Substring(source.IndexOf(var), source.IndexOf(delimiter, source.IndexOf(var))-source.IndexOf(var));
This works, but is there a better, more efficient way to do this?