Hi there,
I've written a small app to get a news headline and story URL out of my MSSQL database and convert it into XML and into an RSS feed. Problem is, of course, that RSS doesn't like '?' or '&' of which my URLs have plenty. If it's an internal url, then no problem, but the minute I use something like: "it doesn't like it!
Now I've written a little function to help me to replace those characters using the replace() function in JScript. This however, just hangs the page until I get a script timout error! Hmmmm.... I've isolated and isolated and it really seems to be the replace function that is at issue. Here's my code:
//I define a new object to hold my conversion values:
function charObject (oldChar, newChar) {
this.oldChar = oldChar;
this.newChar = newChar;
}
//Here is the array of those objects - what to change and what to change to:
var charArray = new Array;
charArray[charArray.length] = new charObject('?','?');
charArray[charArray.length] = new charObject('&','&');
//And this is the replace function:
function replaceChar(thisString) {
//set some variables to ensure correct datatyping
var strReplaceAll = new String(thisString);
var arrLength = charArray.length;
//Now loop through the object array
for (i=0; i<arrLength; i++) {
//check for match
var indexOfMatch = strReplaceAll.indexOf(charArray.oldChar);
//if match, loop through the string while that match exists replacing as we go - the problem seems to be with this loop! even if I just put a Response.Write in there, it still hangs.
while (indexOfMatch != -1) {
//replace first char instance
strReplaceAll = strReplaceAll.replace(charArray.oldChar, charArray.newChar);
//find occurance of next char instance, if it exists
indexOfMatch = strReplaceAll.indexOf(charArray.oldChar);
}
}
//return completed string
return strReplaceAll;
}
For your info, I call this function by doing this:
var urlString = new String(objRec('includeURL'));
var newUrlString = replaceChar(urlString);
where includeURL comes out of my database record (looks like URL above)
Anybody have any idea why this script times out? and do you have any suggestions for how I can work around it?
Thanks SO much!
Pix
I've written a small app to get a news headline and story URL out of my MSSQL database and convert it into XML and into an RSS feed. Problem is, of course, that RSS doesn't like '?' or '&' of which my URLs have plenty. If it's an internal url, then no problem, but the minute I use something like: "it doesn't like it!
Now I've written a little function to help me to replace those characters using the replace() function in JScript. This however, just hangs the page until I get a script timout error! Hmmmm.... I've isolated and isolated and it really seems to be the replace function that is at issue. Here's my code:
//I define a new object to hold my conversion values:
function charObject (oldChar, newChar) {
this.oldChar = oldChar;
this.newChar = newChar;
}
//Here is the array of those objects - what to change and what to change to:
var charArray = new Array;
charArray[charArray.length] = new charObject('?','?');
charArray[charArray.length] = new charObject('&','&');
//And this is the replace function:
function replaceChar(thisString) {
//set some variables to ensure correct datatyping
var strReplaceAll = new String(thisString);
var arrLength = charArray.length;
//Now loop through the object array
for (i=0; i<arrLength; i++) {
//check for match
var indexOfMatch = strReplaceAll.indexOf(charArray.oldChar);
//if match, loop through the string while that match exists replacing as we go - the problem seems to be with this loop! even if I just put a Response.Write in there, it still hangs.
while (indexOfMatch != -1) {
//replace first char instance
strReplaceAll = strReplaceAll.replace(charArray.oldChar, charArray.newChar);
//find occurance of next char instance, if it exists
indexOfMatch = strReplaceAll.indexOf(charArray.oldChar);
}
}
//return completed string
return strReplaceAll;
}
For your info, I call this function by doing this:
var urlString = new String(objRec('includeURL'));
var newUrlString = replaceChar(urlString);
where includeURL comes out of my database record (looks like URL above)
Anybody have any idea why this script times out? and do you have any suggestions for how I can work around it?
Thanks SO much!
Pix