Last active
December 13, 2015 19:58
-
-
Save najlepsiwebdesigner/4966627 to your computer and use it in GitHub Desktop.
javascript insert([index],[string]) method (String.prototype.insert)
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 insert method | |
String.prototype.insert = function (index, string) { | |
if (index > 0) { | |
// necessary fix | |
if (string.charCodeAt(0) == 13){ | |
string = "\n"; | |
} | |
var ret = this.substring(0, index) + string + this.substring(index, this.length); | |
return ret; | |
} else if (index == this.length) { | |
return this + string; | |
} else { | |
return string + this; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment