internationalization - Concat RTL string with LTR string in javascript - Stack Overflow

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

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-13\000004-ر خ-2014.xml

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-13\000004-ر خ-2014.xml

Share Improve this question asked May 1, 2015 at 13:51 user2638062user2638062 732 silver badges8 bronze badges 1
  • May be helpful: stackoverflow./questions/6177294/… .. however, are your numbers written LTR? you may find you have the direction changing within each string too – Paul S. Commented May 1, 2015 at 14:07
Add a ment  | 

1 Answer 1

Reset to default 14

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743724045a4496309.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信