Javascript problem

Status
Not open for further replies.

ph3n0m

New Member
Hi all

Basically I am trying to create a "word replacer" in javascript

I have a string (varying piece of text, X amount of characters long.

I also have a comma seperated array that I have split - my main problem is that I cannot figure out the best way to do a find and replace, matching any of the words in my array to anything in the text string I have.

Anyone have any ideas - or even a working model of what I am looking for?
 

ph3n0m

New Member
Well I got this sorted from through a good friend in Canada

The solution was relatively simple

Code:
<script type="text/javascript">
var longstring = "comma seperate list of words";
var brokenstring = longstring.split(",");
var string = "text to be parsed";
	for (i=0;i<brokenstring.length;i++){
	var newString = string.replace(/brokenstring[i]/gi,"<b>"+brokenstring[i]+"</b>");
	}
	document.write(newString);
</script>
 
Status
Not open for further replies.
Top