2

I have the following url:

localhost:1088/Web_Market/A/Sport.aspx 

It is stored in a string, as below:

string str = "localhost:1088/Web_Market/A/Sport.aspx"

How can I edit the string so it returns the following?

localhost:1088/Web_Market/A/

The full path without the Sport.aspx

1 Answer 1

3

Use below code

Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.LastIndexOf('/') + 1);

This will find substring until the last occurance of "/", which will fetch the URL upto what you needed.

Sign up to request clarification or add additional context in comments.

5 Comments

@DineshPrajapati that's better :)
i did give my feedback , they say: Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score
You can click on tick icon, which will mark it as answer. You can find that icon below down arrow.
@Abrahemhajhle accepting the answer will also give you a reputation boost, so you can work towards being able to upvote! See more here: stackoverflow.com/help/whats-reputation
I get it now, done :) it first i dont know how its work, but now i know thanks to you guys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.