Click to See Complete Forum and Search --> : C# substring type method?


Bugz
November 12th, 2008, 11:16 AM
Is there an easy way to get a substring of a string? I am calling a method that returns back an array of values that look similar to:

keys[0] = "All|All";
keys[1] = "Admin|Admin";
keys[2] = "Shop Floor|Shop Floor";
keys[3] = "Development|Development";
keys[4] = "Front Desk|Front Desk";

When I receive the results, I want to break out the results so that All|All becomes All and Admin|Admin becomes Admin. Is there an easy way to get rid of everything after the "|"?

TheCPUWizard
November 12th, 2008, 12:00 PM
key[n].Split('|')[0]

MMH
November 12th, 2008, 12:08 PM
Can also do this way... though CPUWizard has more elegant solution :)


string[] q = Regex.Split("All|All", "[|]");
MessageBox.Show(q[1].ToString().Trim());

Bugz
November 12th, 2008, 12:58 PM
Its perfect. Thank you!