LoginSignup
0

More than 5 years have passed since last update.

JavaScript で sprintf (のようなもの)を実装する

Last updated at Posted at 2016-08-01

使い方:
var s = _sprintf("aaa %s ccc %s eee", "bbb", "ddd")
(%sしかつかえない。)

function _sprintf(){

    if ( arguments.length < 2 ) {
        return "";
    }
    var s = arguments[0];

    for(i=1; arguments.length > i; i++){
        s = s.replace("%s", arguments[i]);
    }

    return s;
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0