串联从左到右(LTR)和从右到左(RTL)文本 [英] Concatenate left-to-right (LTR) and right-to-left (RTL) text

查看:108
本文介绍了串联从左到右(LTR)和从右到左(RTL)文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎使用 paste 组合从左至右(LTR)和从右至左(RTL)文本可能会为生成的顺序产生意外的结果:

It seems that combining left-to-right (LTR) and right-to-left (RTL) text using paste can produce unexpected results for the resulting order:

(x = paste(c('green', 'أحمر', 'أزرق'), collapse=' ')) # arabic for blue and red
#> [1] "green أحمر أزرق"
paste(x, 'yellow')
#> [1] "green أحمر أزرق yellow"
paste(x, 123)
#> [1] "green أحمر أزرق 123"

对此是否有任何已知的解决方案-即一种确保以与给出的参数相同的顺序进行串联的方法?也许答案是不要连接不同的字母

Is there any known solution to this - i.e. a way to ensure concatenation in the same sequence as the arguments are given? Perhaps the answer is don't concatenate different alphabets!

推荐答案

您可以使用Unicode控制字符从左到右嵌入" u202A (将以下文本从左到右嵌入"):

You may use the Unicode control characters 'left-to-right embedding', u202A ("Treat the following text as embedded left-to-right"):

paste(x, "\u202A", 123)
# [1] "green أحمر أزرق ‭ 123"


另请参见终止显式定向嵌入和覆盖,( u202C ),对 UNICODE双向算法 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆