Convert tabs to spaces, where each tab corresponds to count
spaces.
Use String.prototype.replace()
with a regular expression and String.prototype.repeat()
to replace each tab character with count
spaces.
代码片段
const expandTabs = (str, count) => str.replace(/\t/g, ' '.repeat(count));
使用样例
expandTabs('\t\tlorem', 3); // ' lorem'