¿Cómo hacer "strtolower", "str_replace" y "preg_replace" en javascript?

¿Cómo puedo hacer esto en javascript?

$name = $xml->name;
$file_name = strtolower($name);
$file_name = str_replace(array('-','  ',' ','å','ä','ö'), array('',' ','-','a','a','o'), $file_name);
$file_name = preg_replace("/[^a-z0-9-]+/i", "", $file_name);

preguntado el 31 de julio de 12 a las 12:07

Comienza a leer aquí String methods @ MDN -

$file_name = $file_name.replace(/[^a-z0-9-]+/i, ""); -

2 Respuestas

Mozilla has an amazing reference readily available to you. I've included some link in my response below.

Echa un vistazo a toLocaleLowerCase for lower casing your string. Then move on to reemplazar which is really in many ways very similar to preg_replace in that it is primarily based on regular expressions.

Lots of reading, but it shouldn't be too hard! Good luck!

Respondido 31 Jul 12, 12:07

toLowerCase()   Converts a string to lowercase letters
toUpperCase()   Converts a string to uppercase letters
replace() Searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring
search() Searches for a match between a regular expression and a string, and returns the position of the match

Mira aquí para más detalles: http://www.w3schools.com/jsref/jsref_obj_string.asp

Respondido 31 Jul 12, 12:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.