//입력
HelloWorld!
//출력
HelloWorld!
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', (line) => {
return console.log(line)
})
Interface 인스턴스(rl)을 사용하여 Interface에 내장된 함수를 .on으로 사용한다.
나와있진 않지만, .close도 존재하는데, Interface 인스턴스와 입출력 스트림제어를 종료한다.
line 이벤트는 사용자가 Enter나 Return을 누를때 입력스트림이 발생한다.
//입력
4 5
//출력
a = 4
b = 5
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', (line) => {
input = line.split(' ');
console.log("a = "+input[0]+"\nb = "+input[1])
});
//입력
string 5
//출력
stringstringstringstringstring
let input = [];
rl.on('line', function (line) {
input = line.split(' ');
for(var i = 0; i<input[1]; i++){
process.stdout.write(input[0])
}
})
( rl 인스턴스를 불러오는 과정은 생략 )
//입력
aBcDeFg
//출력
AbCdEfG
var answer=[];
rl.on('line',(line)=> {
for(let x of line){
if(x===x.toUpperCase()){
answer += x.toLowerCase();
}else answer += x.toUpperCase()
}
console.log(answer);
})
( rl 인스턴스를 불러오는 과정은 생략 )
str.toUpperCase()는 문자열을 대문자로 바꾼다.
str.toLowerCase()는 문자열을 소문자로 바꾼다.
//출력
!@#$%^&*(\'"<>?:;
rl.on('close', function () {
console.log("!@#$%^&*(\\'\"\<>?:;")
});
( rl 인스턴스를 불러오는 과정은 생략 )