Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
How to differentiate between existing newlines and \n in variable?

I have a text like this:

123\n456
789

How can I save this text in a variable without loosing the information if the newline was made with \n or with a existing newline? If I save it with template strings like this:

var str = `123\n456
789`;

the saved variable will be 123\n456\n789. Is there a way to differentiate between the two?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

How can I save this text in a variable, such as a string containing the sequence \n and not a line break?

You must escape the backslash in the string literal:

 var str = "\n"

or you can use a template literal tagged with String.raw :

 var str = String.raw("\n");
about 4 years ago · Juan Pablo Isaza Denunciar

0

Is this what you are looking for?

 var str = `123\\n456 789`; console.log(str);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda