标签:UNC log func return hsi code ide head end
function trim(str) { return str.replace(/\s*/g, ‘‘); } console.log(‘=‘ + trim(‘ Hello World ! ‘) + ‘=‘); // =HelloWorld!=
function trimMiddle(str) { let head = str.match(/^\s*\S*/)[0]; let end = str.match(/\S*\s*$/)[0]; let middle = str.replace(/(^\s*\S*)|(\S*\s*$)/g, ‘‘).replace(/\s*/g, ‘‘); return head + middle + end; } console.log(‘=‘ + trimMiddle(‘ Hello World ! ‘) + ‘=‘); // = HelloWorld! =
function trimBothSides(str) { return str.replace(/^\s*|\s*$/g, ‘‘); } console.log(‘=‘ + trimBothSides(‘ Hello World! ‘) + ‘=‘); // =Hello World!=
console.log(‘=‘ + ‘ Hello World ! ‘.trim() + ‘=‘); // =Hello World !=
function trimLeft(str) { return str.replace(/^\s*/, ‘‘); } console.log(‘=‘ + trimLeft(‘ Hello World! ‘) + ‘=‘); // =Hello World! =
console.log(‘=‘ + ‘ Hello World ! ‘.trimLeft() + ‘=‘); // =Hello World ! =
function trimRight(str) { return str.replace(/\s*$/, ‘‘); } console.log(‘=‘ + trimRight(‘ Hello World! ‘) + ‘=‘); // = Hello World!=
console.log(‘=‘ + ‘ Hello World ! ‘.trimRight() + ‘=‘); // = Hello World !=
标签:UNC log func return hsi code ide head end
原文地址:https://www.cnblogs.com/yingtoumao/p/11520446.html