Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: replace()

  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy replace()

    Hi, I am really struggling with a solution for a replacment in a string:

    I am tring to replace the IMG tag within a sting containing a whole bunch of html code.

    All my functions calls work fine. What I am left with is a different IMG tag depending on weather the image is clickable or not.

    function getImageBio(htmlIMG)
    {
    var startHREF = "";
    var endHREF = "";
    var tempIMG = "";
    var bioView = "";

    startHREF = htmlIMG.indexOf("<a href=\"bios");
    endHREF = htmlIMG.indexOf("Biography'><\a>");
    tempIMG = htmlIMG.substring(startHREF.endHREF);

    var bioFile = getBio(htmlIMG);
    var picFile = getPic(htmlIMG);

    if(bioFile == "bios/.")
    bioView = viewNoBio(picFile);
    else
    bioView = viewBio(picFile, bioFile);

    htmlIMG.replace(tempIMG, bioView);

    return(bioView);
    }

    The htmlING.replace is where I am getting lost. I need a way to replace the tempIMG string with in the htmlIMG string with the bioView string.

    Hope this isn't too confusing. I just can't figure it out. Can anyone help???

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The replace method works like indexOf and substring - it returns the result:
    Code:
    htmlIMG=htmlIMG.replace(tempIMG, bioView);
    Edit: And the tempIMG should be a RegExp -object.
    Last edited by Danne; 01-16-2004 at 03:55 PM.
    /Daniel

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    u migth wanna put this:

    var temp="Biography'><\a>";
    endHREF = htmlIMG.indexOf(temp)+temp.length;

    instead of the line:

    endHREF = htmlIMG.indexOf("Biography'><\a>");

    it sort of depends if u want the substring to include the text
    Biography'><\a>" or not.


  •  

    Posting Permissions

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