Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Insert one string into another.

  1. #11
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Just one minor problem Twey , your code will fail in cases where several place-holders appear consecutively (eg. "%LANG%%SOMETHING%").

  2. #12
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    True that. *edit*
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #13
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Is there any chance you could explain what is going on here line by line? There's a lot of stuff in there I'm completely unfamiliar with.
    I think the OP is looking for an example script.
    - Mike

  4. #14
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I gave one...
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #15
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Usage of the script.

    EDIT: Sorry! Missed the original post, my bad. Well I feel stupid now.
    - Mike

  6. #16
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    Okay, so this is the usage, right? :

    Code:
    Lang.interpolate("http://www.example.com/%LANG%/hello.html", {
        'LANG' : 'es'
      });
    If the first argument, the URL, is coming from the URL of the current page, how do get from that to "http://www.example.com/%LANG%/hello.html"?

  7. #17
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    Seems that this will be sufficient for you:
    Code:
    function reRoot(url, root)
    {
        return url.replace(/^([a-z]+:\/\/[^\/]+)(.*)/i, "$1" + root + "$2");
    }
    var newUrl = reRoot(document.location.href, "/newdir");

  8. The Following User Says Thank You to DimX For This Useful Post:

    jlizarraga (08-13-2008)

  9. #18
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    That's perfect, thank you!

  10. #19
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    I made this with your help:

    http://ballhonda.autofusion.com/includes/gs.js



    Thanks again!

  11. #20
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Quote Originally Posted by mburt View Post
    You might find 5 people on this entire forum who think that code is simple.
    It is simple

    Example usage:
    Code:
    var dirs = ["", "foo/", "bar/", "foo/baz/"];
    for(var i = 0; i < dirs.length; ++i)
      alert(Lang.interpolate("http://www.example.com/%DIR%hello.html", {
        "DIR": dirs[i]
      }));
    Last edited by Trinithis; 08-13-2008 at 07:21 AM. Reason: quoted the object property for clarity
    Trinithis

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •