Created
February 1, 2011 01:44
-
-
Save rauluranga/805253 to your computer and use it in GitHub Desktop.
replace all the '?' in the passed string with the corresponding parameter
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
/** | |
* @example | |
var sql:String = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?"; | |
trace(binding(sql, 3, "live", "Rick")); | |
//outputs SELECT * FROM some_table WHERE id = 3 AND status = live AND author = Rick | |
*/ | |
public static function binding(msg:String, ... rest):String | |
{ | |
for (var i:int = 0;i < rest.length;i++) { | |
msg = msg.replace(new RegExp("\\?", "i"), rest[i]); | |
} | |
return msg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment