본문 바로가기
Programming/Angular

공백제거하기.

by Deafhong 2017. 8. 30.
반응형

[공백제거하기 by AngularJS 4]


모든 공백제거하기.

const string = ' Test Message ';
const resultString = string.replace(/(\s*)/g, '');
console.log(resultString);

//Chrome Developer Test 용.
console.time('모든 공백제거하기');
var string = ' Test Message ';
var resultString = string.replace(/(\s*)/g, '');
console.log(resultString);
console.timeEnd('모든 공백제거하기');

앞 공백제거하기.

const string = ' Test Message ';
const resultString = string.replace(/^\s*/, '');
console.log(resultString);

//Chrome Developer Test 용.
console.time('앞 공백제거하기');
var string = ' Test Message ';
var resultString = string.replace(/^\s*/, '');
console.log(resultString);
console.timeEnd('앞 공백제거하기');

뒤 공백 제거하기.

const string = ' Test Message ';
const resultString = string.replace(/(\s$)/, '');
console.log(resultString);

//Chrome Developer Test 용.
console.time('뒤 공백제거하기');
var string = ' Test Message ';
var resultString = string.replace(/(\s$)/, '');
console.log(resultString);
console.timeEnd('뒤 공백제거하기');

앞, 뒤 공백 제거하기

const string = ' Test Message ';
const resultString = string.replace(/(^\s*)|(\s*$)/g, '');
console.log(resultString);

//Chrome Developer Test 용.
console.time('앞뒤 공백제거하기');
var string = ' Test Message ';
var resultString = string.replace(/(^\s*)|(\s*$)/g, '');
console.log(resultString);
console.timeEnd('앞뒤 공백제거하기');



반응형