Path.Combine equivalent for URLs?

Discussion in 'ASP .Net' started by Brian Vallelunga, Apr 9, 2007.

  1. Is there a way to easily combine two parts of a url? Something like
    Path.Combine for system files would be perfect.

    So if I have:

    string s1 = "http://mydomain.com/"
    string s2 = "/hello/image.jpg"

    I would want the combination to not have the double '//' in the middle
    that a normal concatenation would give.
    Brian Vallelunga, Apr 9, 2007
    #1
    1. Advertising

  2. You could just trim the second string and join them together

    string s1 = "http://mydomain.com/";
    string s2 = "/hello/image.jpg";
    string s3 = s2.Remove(0,1);
    string s4 = s1 += s3;
    Label1.Text = s4;

    Regards

    John Timney (MVP)
    http://www.johntimney.com
    http://www.johntimney.com/blog


    "Brian Vallelunga" <> wrote in message
    news:...
    > Is there a way to easily combine two parts of a url? Something like
    > Path.Combine for system files would be perfect.
    >
    > So if I have:
    >
    > string s1 = "http://mydomain.com/"
    > string s2 = "/hello/image.jpg"
    >
    > I would want the combination to not have the double '//' in the middle
    > that a normal concatenation would give.
    >
    John Timney \(MVP\), Apr 9, 2007
    #2
    1. Advertising

  3. On Apr 9, 5:11 pm, "John Timney \(MVP\)" <>
    wrote:
    > You could just trim the second string and join them together
    >
    > string s1 = "http://mydomain.com/";
    > string s2 = "/hello/image.jpg";
    > string s3 = s2.Remove(0,1);
    > string s4 = s1 += s3;
    > Label1.Text = s4;
    >
    > Regards
    >
    > John Timney (MVP)http://www.johntimney.comhttp://www.johntimney.com/blog


    That's essentially what I'm doing now, but I was hoping for something
    more robust, that could accomodate other people putting in various
    strings.
    Brian Vallelunga, Apr 9, 2007
    #3
  4. I don't believe theres anything that intelligent really. To be honest its
    not worth worrying about as // is valid in an http path.

    Regards

    John Timney (MVP)
    http://www.johntimney.com
    http://www.johntimney.com/blog


    "Brian Vallelunga" <> wrote in message
    news:...
    > On Apr 9, 5:11 pm, "John Timney \(MVP\)" <>
    > wrote:
    >> You could just trim the second string and join them together
    >>
    >> string s1 = "http://mydomain.com/";
    >> string s2 = "/hello/image.jpg";
    >> string s3 = s2.Remove(0,1);
    >> string s4 = s1 += s3;
    >> Label1.Text = s4;
    >>
    >> Regards
    >>
    >> John Timney (MVP)http://www.johntimney.comhttp://www.johntimney.com/blog

    >
    > That's essentially what I'm doing now, but I was hoping for something
    > more robust, that could accomodate other people putting in various
    > strings.
    >
    John Timney \(MVP\), Apr 10, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kaidi
    Replies:
    5
    Views:
    454
    Andrew Thompson
    Jan 4, 2004
  2. Nathan Sokalski

    Converting Relative URLs into Absolute URLs

    Nathan Sokalski, Aug 11, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    730
    Sriram Srivatsan
    Aug 12, 2008
  3. Adam Monsen

    JDBC URLs ...not really URLs?

    Adam Monsen, Feb 6, 2009, in forum: Java
    Replies:
    11
    Views:
    6,116
    Adam Monsen
    Feb 8, 2009
  4. Alia K
    Replies:
    6
    Views:
    570
    Ben Bacarisse
    Feb 4, 2011
  5. Steve T.

    dynamic URLS convert to static URLS for search engines

    Steve T., Mar 1, 2004, in forum: ASP .Net Web Services
    Replies:
    7
    Views:
    272
    Steve T.
    Mar 4, 2004
Loading...

Share This Page