Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
804 views
in Technique[技术] by (71.8m points)

internationalization - Concat RTL string with LTR string in javascript

I'm facing trouble in concatenating Arabic string with English string but their order is being messed!

I tried + operator and str1.concat(..) but nothing works for me.

var a = 'english'
var b = '?.?-000082-13'
var c = '000004-? ?-2014.xml'

//var myCoolString =a + '\' + b + '\' + c;

var myCoolString =a.concat("",b,"",c) 

document.getElementsByTagName('output')[0].innerHTML = myCoolString;

The result was like this: english?.?-000082-1300004-? ?-2014.xml

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The characters your are looking for are u202A, u202B and u202C

function wrap_dir(dir, str) {
    if (dir === 'rtl') return 'u202B' + str + 'u202C';
    return 'u202A' + str + 'u202C';
}


wrap_dir('ltr', a) + wrap_dir('ltr', '\') + wrap_dir('rtl', b) + wrap_dir('ltr', '\') + wrap_dir('ltr', c);
// "?english?????.?-000082-13????000004-? ?-2014.xml?"

Not sure why c wanted to be LTR, maybe because it ends .xml?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...