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

131
Visualizações
Concatenate numeric value to the right side of an Arabic String in JS

var data = "عينات";

var num = "123";

var res = data + num; // returns عينات123

I am trying to concatenate numbers to the right side of the arabic text, but its jumping to the left side, also tried reversing the string, but didn't help.

Please suggest a solution in Javascript.

Thanks in Advance!

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

0

You can make use of Directional_Formatting_Codes:

  • LRE U+202A LEFT-TO-RIGHT EMBEDDING Treat the following text as embedded left-to-right.
  • PDF U+202C POP DIRECTIONAL FORMATTING End the scope of the last LRE, RLE, RLO, or LRO.

var data = "عينات";
var num = "123";
var res = "\u202A" + data + "\u202C" + num
console.log(res);

about 4 years ago · Juan Pablo Isaza Relatório

0

Another answer suggested adding control characters into the text, but as someone commented this approach has it's downsides.

The reason you get the digits to the left no matter the order of the string is because you are using an LTR element (or the browser's console which is always LTR). Then if the digits come first they start at the left, and if the arabic letters come first they start at the right because arabic letters have "hard" RTL directionning even inside an LTR element.

However, if you are using an RTL element and put the digits first, it will show up as intended:

<div dir="rtl">123عينات</div>

Or dynamically with JavaScript:

var data = "عينات";
var num = "123";
var res = num + data;

var el = document.createElement('div');
el.dir = "rtl";
el.textContent = res;
document.body.append(el);

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