连接从左到右 (LTR) 和从右到左 (RTL) 的文本 [英] Concatenate left-to-right (LTR) and right-to-left (RTL) text
问题描述
似乎使用 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 控制字符 'left-to-right embedding', 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 双向算法的详尽描述,以及此处.
See also Terminating Explicit Directional Embeddings and Overrides, (u202C
), a thorough description on UNICODE BIDIRECTIONAL ALGORITHM, and here.
这篇关于连接从左到右 (LTR) 和从右到左 (RTL) 的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!