我正在寻找一个很好的JavaScript等价的C/PHP printf()或C#/ Java程序员String.Format()(IFormatProvider对于.NET).
我的基本要求是现在有一千个数字分隔符格式,但处理许多组合(包括日期)的东西会很好.
我意识到Microsoft的Ajax库提供了一个版本String.Format(),但我们不希望该框架的整个开销.
我想要一个模仿python .format()函数的javascript函数
.format(*args, **kwargs)
Run Code Online (Sandbox Code Playgroud)
前一个问题为'.format(*args)提供了一个可能的(但不是完整的)解决方案
JavaScript等效于printf/string.format
我希望能够做到
"hello {} and {}".format("you", "bob"
==> hello you and bob
"hello {0} and {1}".format("you", "bob")
==> hello you and bob
"hello {0} and {1} and {a}".format("you", "bob",a="mary")
==> hello you and bob and mary
"hello {0} and {1} and {a} and {2}".format("you", "bob","jill",a="mary")
==> hello you and bob and mary and jill
Run Code Online (Sandbox Code Playgroud)
我意识到这是一个很高的订单,但也许某个地方有一个包含关键字参数的完整(或至少部分)解决方案.
哦,我听说AJAX和JQuery可能有这方面的方法,但我希望能够在没有这些开销的情况下完成它.
特别是,我希望能够将其与google doc的脚本一起使用.
谢谢