...

View Full Version : replace()



Missy_K
01-16-2004, 02:42 PM
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???

Danne
01-16-2004, 03:29 PM
The replace method works like indexOf and substring - it returns the result:


htmlIMG=htmlIMG.replace(tempIMG, bioView);


And the tempIMG should be a RegExp (http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/regexp.html#1193136) -object.

Garadon
01-16-2004, 03:52 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum