0

I have a url that looks like this

https://domain1.com/go/2345/Default.aspx?c%7c2vCZVIjuUzLTfgsgagasgsgasgsagag

I would like to be able to replace the domain1.com for domain12.com so it would look like this https://domain12.com/go/2453545/Default.aspx?

How I can replace only the domain1.com part? Quick note : Everything after the "go/"changes every time I open the browser

I try this

I get the Url from the browser

string getUrl = Url;

then I replace the value

string newUrl = getUrl .Replace(getUrl .Substring(url.IndexOf(go)
1
  • Please don't remove highlighting from your fake "links" because they act as real links Commented Apr 2, 2020 at 0:22

1 Answer 1

2
var u = "https://domain1.com/go/2345/Default.aspx?c%7c2vCZVIjuUzLTfgsgagasgsgasgsagag";
var uri = new Uri(u);
var path = 
    uri.PathAndQuery.Substring(0, uri.PathAndQuery.Length - uri.Query.Length);
string newUrl = "https://domain2.com" + path;
Console.WriteLine(newUrl);
// OUTPUT:  https://domain2.com/go/2345/Default.aspx
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.