Pregunta: | 18418 - TRIM |
Autor: | Rocío |
Quisiera encontrar en javascript una función equivalente al trim.
¿alguién me podría ayudar?... |
Respuesta: | J. A. |
Solo tienes que incluir esta funcion en tu codigo:
function trim(strTexto) { while(strTexto.charCodeAt(0) == 32) strTexto = strTexto.substring(1, strTexto.length); while(strTexto.charCodeAt(strTexto.length - 1) == 32) strTexto = strTexto.substring(0, strTexto.length - 1); return strTexto; } , y llamarla de esta manera: var textoFinal = trim(textoInicial); |