将制表符扩展为空格
将制表符转换为空格,其中每个制表符对应 count 个空格。
- 使用
String.prototype.replace()方法与正则表达式和String.prototype.repeat()方法,将每个制表符字符替换为count个空格。
const expandTabs = (str, count) => str.replace(/\t/g, ' '.repeat(count));
expandTabs('\t\tlorem', 3); // ' lorem'