Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

324
Visualizações
Adding a multiple space character's in nodejs using replace method

I have the following variable.

var s = 'Hi Al !'

Which i would like to convert to

'Hi    Al !'

I.E. basically add 4 space characters and hence taught i could do the following:-

var new_var = s.replace('Hi', 'Hi\s\s\s\s');

But the above only gives me the output Hissss Al !, which is not what i want. How do i add 4 space characters to my string ?

I have also tried var new_var = s.replace('Hi', 'Hi\t');

But the output has about 6-7 spaces.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Just use the space character:

var s = 'Hi Al !'
var new_var = s.replace('Hi', 'Hi    ');
console.log(new_var)

about 4 years ago · Juan Pablo Isaza Relatório

0

Using \s matches a whitespace char using a regular expression. If you use that in the replacement, it will just be s

If there is a variable number of spaces after Hi, and you want to change that to always have 4 spaces, you can match 1 or more whitespace chars and use 4 spaces in the replacement.

var s = 'Hi              Al !';
var new_var = s.replace(/Hi\s+/, 'Hi    ');
console.log(new_var)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda