...

View Full Version : string.replace() problemo



Gmakermaniac!!!
10-24-2004, 04:37 AM
The sting handeling function replace(RegExp, replacetext) dosn't seem to be working properly. Okay, here's my problem, I have a textarea on my page and I save it's data to a cookie. When I load the cookie, it's fine, as long as it's on one line. If the user presses enter and saves the cookie, somehow the new line get's replaced with "__". This is not good if your trying to save about 100 lines of code. it all becomes 1 line with "__" wherever "\n" was. in the open cookie function I made, I tried to replace "__" with "\n" but nothing happens. :confused:


function savehtml()
{
document.cookie = "Html=" + htmlcode.value + ";";
}
function openhtml()
{
htmlstart = document.cookie.indexOf("=") + 1;
htmlend = document.cookie.indexOf(";");
var temp = new String();
temp = document.cookie.substring(htmlstart, htmlend);
temp.replace("__", "\n");
htmlcode.value = temp;
}

any Ideas?

A1ien51
10-24-2004, 06:08 AM
var regEx = /__/gi;
temp.replace(regEx, "\n");

liorean
10-24-2004, 12:39 PM
Replace is nondestructive - it returns the new value, but the variable does still contain the original.

Gmakermaniac!!!
10-24-2004, 02:26 PM
Thanks, I'll see what I can do. :rolleyes:

10 minutes later: Yay, it works! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum