串联左右对齐的字符类型 [英] Concatenating left and right-aligned character types
问题描述
似乎字符类型的组合可能会为显式粘贴操作的结果顺序产生意外结果:
It seems that a combinations of character types can produce unexpected results for the resulting order of an explicit paste operation:
(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
),a UNICODE双向算法和
See also Terminating Explicit Directional Embeddings and Overrides, (u202C
), a thorough description on UNICODE BIDIRECTIONAL ALGORITHM, and here.
这篇关于串联左右对齐的字符类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!