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

209
Vistas
how to get special character from string in nodejs and replace

how to find specific special character from string and replace it to unicode \u0026 + = \u002B

replace only these special character : [$, &, +, #]

example : "HELLO JAMES (WITH ME YOUR) \n+++ SEE & FIELD 4-B +++

MY code

 var char = '+';      
          var saa =char.charCodeAt(0);
          console.log(saa)
          var codeHex = saa.toString(16).toUpperCase();
          while (codeHex.length < 4) {
            codeHex = "0" + codeHex;
        }    
        var afteruni = name.replaceAll('\+','\\u'+codeHex) 

String.prototype.replaceAll = function(search, replacement) {
  var target = this;
  return target.replace(new RegExp(search, 'g'), replacement);
};

i want like this :

"HELLO JAMES (WITH ME YOUR) \n\u002B\u002B\u002B SEE \u0026 FIELD 4-B \u002B\u002B\u002B"

ERROR : Invalid regular expression: /+/: Nothing to repeat\

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

0

you don't need to redefined replaceAll - why do that? replaceAll will already give you a correct response :

just replace line: var afteruni = name.replaceAll('\+','\\u'+codeHex)

with var afteruni = name.replaceAll(/\+/g,'\\u'+codeHex)

iv'e run that in my PC and it is working.

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