728x90
'-' 특수문자 제거 | input.replace(/\-/g,''); |
시작 부분의 공백 제거 | input .replace(/^\s+/,''); |
끝 부분의 공백 제거 | input .replace(/\s+$/,''); |
앞뒤 둘 공백 제거 | input .replace(/^\s+|\s+$/g,''); |
출력값의 모든 공백 제거 | input .replace(/\s/g,''); |
\n(줄바꿈 문자) 제거 | input .replace(/\n/g,''); |
\r(리턴 문자) 제거 | input .replace(/\r/g,''); |
백준 문제 풀 때나 배열로 받아온 문자를 출력할 때 출력값 뒤에 \r이나 \n이 붙는 경우가 있다.
위의 코드를 이용해 이 부분을 제거하여 깔끔하게 출력이 가능
728x90
'짤막한 지식' 카테고리의 다른 글
Makefile:{line-number}: *** missing separator. Stop. (1) | 2024.02.26 |
---|---|
console.log와 process.stdout.write 차이점 (1) | 2024.02.23 |