faqts

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 18 people (28%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How do I remove all accent from a string ?
Is there a STRTR function like in php ?

May 12th, 2008 21:24
i can do it, ben joe, http://us2.php.net/manual/en/function.strtr.php


/*
 * STRTR as in php :  This function returns a copy of str, translating
 * all occurrences of each character in from to the corresponding
 * character in to
 */
String.prototype.strtr = function(from, to)
{
	var s, p, c1, c2, c3;
	if(! this.length || from.length != to.length) return;
	s = this;	
	for(var i=0; i<str.length; i++)
	{
		c1 = str.substr(i,1);
		for(var j=0; j<from.length; j++)
		{
			c2 = from.substr(j,1);
			c3 = to.substr(j,1);
			if(c1 == c2)
			{
				p = new RegExp(c2,'gi');
				s = s.replace(p,c3);
			}
		}
	}
	return s;
}
/*
 * REMOVEACCENTS: This function returns a copy of str, removing
 * all accents in it
 */
function removeaccents(string) {
 return string.strtr(
"ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ",
"SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy");
http://www.stupidarticles.com
http://www.halazona.com
http://www.shikapika.com
http://www.stakoza.com
http://www.uploadarticles.com
http://www.ganazat.com
http://www.damima.com
http://www.tarabiza.com
http://www.articlesxarticles.com
http://www.articlesfreedirectory.com
}