我知道如何使用util.format()使用%f,%d等格式化字符串。有人可以告诉我哪个是可以从字符串扫描(而不是从控制台输入)启用的补充功能。Node.js中util.format()的补充函数
例如:
运行...
const util = require('util');
var weatherStr = util.format(`The temperature at %d o' clock was %f deg. C and the humidity was %f.`, 5, 23.9, 0.5);
console.log(weatherStr);
... ...产生
The temperature at 5 o' clock was 23.9 deg. C and the humidity was 0.5.
我期待一个实用程序函数,它会工作,使得运行以下代码...
const util = require('util');
var weatherStr = 'The temperature at 5 o' clock was 23.9 deg. C and the humidity was 0.5.';
console.log(util.????(tempStr, `humidity was %f.`));
...生成...
0.5
这是一个util函数吗?我不认为“parseFloat”会起作用,因为它会提取23.9。
我是新来的JS和节点,但我希望有一个“扫描”功能。我知道有一个scanf npm库,但它似乎与控制台输入,而不是现有的字符串。我一直在搜索JS和Node函数中的“%f”,并且令人惊讶的是util.format似乎是唯一一个提及它的。