[Javascript] Replace

THerman at jerviswebb.com THerman at jerviswebb.com
Thu Jan 16 15:17:56 CST 2003


Thanks Peter I appriciate your help.

-----Original Message-----
From: Peter Brunone [mailto:peter at brunone.com]
Sent: Thursday, January 16, 2003 3:52 PM
To: javascript at LaTech.edu
Subject: RE: [Javascript] Replace


Terry,

	I don't know of one off the top of my head, but here's something I
whipped
up that will replace one character at a time (i.e. it will replace all
instances of "q", but it won't replace "qa").

function replaceChar(theString, oldChar, newChar) {
	var i = 0;
	var j = theString.length;

	for(i=0; i < theString.length; i++) {
		if(theString.charAt(i) == oldChar) {
			theString = theString.substring(0,i) + newChar +
theString.substring(i+1,theString.length);
			if(i > j) { // loop-killer, just in case we mess
with the code
				break;
				}
			}
		}
	return theString;
	}

	(watch for line wrapping)

	For example, to replace all carriage returns with a string of zero
length,
you would say replaceChar(thisVariableFullOfStuff, "\n" ,""); let me know if
you have any problems with it.

-Peter
----------------------
Do you Yahoo?
Does your mother know?
----------------------

|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|Behalf Of THerman at jerviswebb.com
|
|Hello
|can someone direct me to a replace function that takes care of quotes,
|carrige returns , line feeds
|
|thanks
|terry

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list