Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace problem

Status
Not open for further replies.

MJB3K

Programmer
Joined
Jul 16, 2004
Messages
524
Location
GB
Hi, i have this function i am making and would like to convert all the occurances of --------[newstep]-------- into <table><tr><td bgcolor=#CCCCCC>test</td></tr></table>
Code:
function updatePreview(){
	var tf = document.form1;
	var p = document.getElementById("preview");
	
	var theTxt = tf.tutorial.value;
	theTxt.replace(/--------[newstep]--------/,"<table><tr><td bgcolor=#CCCCCC>test</td></tr></table>");
	
	
	var str = theTxt; // + pp;
	
	p.innerHTML = str;
}
any ideas??

Regards,

Martin

Computing Help And Info:
 
This.
[tt]
var theTxt = tf.tutorial.value;
[red]var str=[/red]theTxt.replace(/--------[red]\[/red][newstep]--------/,"<table><tr><td bgcolor=#CCCCCC>test</td></tr></table>"); // + pp;
[/tt]
It replaces the first encounter of the combination of characters you've in mind. If you want to replace every instance appeared in the theTxt, add a global flag, like this.
[tt]
var str=theTxt.replace(/--------\[newstep]--------/[blue]g[/blue],"<table><tr><td bgcolor=#CCCCCC>test</td></tr></table>"); // + pp;
[/tt]
 
that works great. just another question. how could i change multiple strings??

e.g. i would like to convert all the \n into <br /> and --------[newpage]-------- into <table><tr><td bgcolor=#666666>test</td></tr></table> at the same time. is this posible?

Regards,

Martin

Computing Help And Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top