Skip to content

Instantly share code, notes, and snippets.

@rauluranga
Created February 1, 2011 01:44
Show Gist options
  • Save rauluranga/805253 to your computer and use it in GitHub Desktop.
Save rauluranga/805253 to your computer and use it in GitHub Desktop.
replace all the '?' in the passed string with the corresponding parameter
/**
* @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