Created
September 1, 2015 02:55
-
-
Save grimmdev/fd65e8608cfbd6ff377f to your computer and use it in GitHub Desktop.
DroidScript/Javascript Functions
This file contains hidden or 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.format = function() { | |
// The string containing the format items (e.g. "{0}") | |
// will and always has to be the first argument. | |
var theString = arguments[0]; | |
// start with the second argument (i = 1) | |
for (var i = 1; i < arguments.length; i++) { | |
// "gm" = RegEx options for Global search (more than one instance) | |
// and for Multiline search | |
var regEx = new RegExp("\\{" + (i - 1) + "\\}", "gm"); | |
theString = theString.replace(regEx, arguments[i]); | |
} | |
return theString; | |
} | |
// Example | |
var test = String.format('<a href="{0}/{1}/{2}" title="{2}">{2}</a>', | |
var1, var2, var3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment