Last active
January 19, 2017 23:06
-
-
Save donpandix/2850054a1121bc6b9c60 to your computer and use it in GitHub Desktop.
Trim a cadena de texto (por la izquierda, derecha y ambos lados), asigna el método a todas las cadenas de texto por medio de la implementación al objeto String directamente
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.trim = function() { | |
return this.replace(/^\s+|\s+$/g,""); | |
} | |
String.prototype.ltrim = function() { | |
return this.replace(/^\s+/,""); | |
} | |
String.prototype.rtrim = function() { | |
return this.replace(/\s+$/,""); | |
} | |
/* | |
// Ejemplo de uso: cadenaDeTexto.trim(); | |
var cadena = " esta es una cadena "; | |
cadena = cadena.trim(); | |
// la variable cadena tiene el valor "esta es una cadena" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment