If i have a such as path \-edd\fold\fold2\ or parent\fold\fold2\ how do i get the value of -edd or parent from the path? I tried .Root but that just returns C:\, its a relative path

If i have a such as path \-edd\fold\fold2\ or parent\fold\fold2\ how do i get the value of -edd or parent from the path?  I tried .Root but that just returns C:\, its a relative path
cbruneAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Todd GerbertIT ConsultantCommented:
You can split the string on the \ and get the first element of the resulting array.
@"\-edd\fold\fold2\".Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries)[0];

Open in new window


Of course, in reality, you check to make sure the Split method returned an array with at least one elements before you try to refer to it.
0
Todd GerbertIT ConsultantCommented:
Something along the lines of:
string topLevel = String.Empty;
string path = @"\-edd\fold\fold2\";
string[] pieces = path.Split(new char[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
if (pieces.Length > 0)
	topLevel = pieces[0];

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cbruneAuthor Commented:
now how would i strip out the \-edd out of the path and have \fold\fold2?
0
Todd GerbertIT ConsultantCommented:
Have a look at arrays in C# (http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx) and the String.Split() method (http://msdn.microsoft.com/en-us/library/ms131448.aspx).

Try using my example above (http:#a35325655) and put a break-point on line 3, and then inspect the contents of the pieces string array.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.