-1

This is my code:

process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (text) {
    text.replace(/\r?\n|\r/g, "");
    console.log("Command: " + text + "textthatshouldbeinthesameline");
    if (text == 'quit') {
        console.log("Quitting");
        done();
    }
});

function done() {
  console.log('Now that process.stdin is paused, there is nothing more to do.');
  process.exit();
}

And this is what happens:

enter image description here

It seems like there are some line breaks, I tried to replace them, but as you see: without effect.

When I type "quit" it also isn't recognized by if statement.

Gabriel Llamas
  • 18,244
  • 26
  • 87
  • 112
Piotrek
  • 10,919
  • 18
  • 73
  • 136

1 Answers1

6

replace doesn't change the string, as strings are immutable. It returns a new string.

Change

text.replace(/\r?\n|\r/g, "");

to

text = text.replace(/\r?\n|\r/g, "");
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758