Created
November 7, 2014 16:48
-
-
Save cristiandley/2021c5a2bfcfb1282e2f to your computer and use it in GitHub Desktop.
Replace an specific kind of chars
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
/** | |
* REPLACE ALL CHARS | |
* (but the name is not.... i know!) | |
*/ | |
String.prototype.replaceChar=function(position, char) { | |
return this.substr(0, position) + char + this.substr(position, this.length); | |
} | |
String.prototype.replaceAllChars = function(thisChar, forThisChar){ | |
var lngChar = forThisChar.length; | |
var _tmp = this; | |
for (var position=0; position < _tmp.length; position++){ | |
if(_tmp[position] == thisChar){ | |
_tmp = _tmp.replaceChar(position, forThisChar); | |
position = position+(lngChar+1); | |
} | |
} | |
return _tmp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment