How to trim part of a string?

I have a string that looks like this:

/xyz/Documents/Test Folder

The sting is dynamically generated from a request string.  I would like to remove the left part of the string up to the second "/".  So the resulting string would appear as:  

Documents/Test Folder

How do I remove just the "/xyz/" part of the string. Where "xyz" is dynamic text.  I know for sure there will always be two "/"s at the beginning.

Thank you
greddinAsked:
Who is Participating?
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.

Meir RivkinFull stack Software EngineerCommented:
example:
string str = "/xyz/Documents/Test Folder";
            var new_str = string.Join("//", str.Split('/').Skip(2).ToArray());

Open in new window

0
greddinAuthor Commented:
@sedgwick:  I'm getting an error when using your code:

CS0246: The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?)

I'm attempting to use this in a user control (.ascx).  Here's what I have so far.

<%@ Control Language="C#" compilationMode="Always" %>
<%
string str = Request.QueryString["RootFolder"];
var new_str = string.Join("//", str.Split('/').Skip(2).ToArray());
Response.Write(new_str);
%>

Open in new window


Thank you again.
0
Meir RivkinFull stack Software EngineerCommented:
change var to string
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

greddinAuthor Commented:
Ok, changed var to string.  Now getting a different error.

CS0117: 'System.Array' does not contain a definition for 'Skip'
0
Meir RivkinFull stack Software EngineerCommented:
add
using System.Linq;

Open in new window

0
greddinAuthor Commented:
I get a Syntax error '(' expected when I add the System.Linq line.  Here's my full code.

<%@ Control Language="C#" compilationMode="Always" %>
<%
using System.Linq;
string str = Request.QueryString["RootFolder"];
string new_str = string.Join("//", str.Split('/').Skip(2).ToArray());
Response.Write(new_str);
%>

Open in new window


Thanks for all your help.
0
Julian HansenCommented:
Try this
<%@ Control Language="C#" compilationMode="Always" %>
<%
string str = Request.QueryString["RootFolder"];
//Search for the first '/' starting at char 1 and then take the 
//substring immediately after this.
string new_str = str.Substring(str.IndexOf("/", 1)+1);
Response.Write(new_str);
%>

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
greddinAuthor Commented:
Thanks!
0
Julian HansenCommented:
You are welcome - thanks for the points.
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
ASP.NET

From novice to tech pro — start learning today.