这是一个en dash:
en破折号、en rule或nut破折号-传统上是em破折号的一半宽度.
关于ASC的注释
以下是直接来自shQuote()
docs的示例:
## Backslashes followed by up to three numbers are interpreted as
## octal notation for ASCII characters.
"\110\145\154\154\157\40\127\157\162\154\144\41"
# [1] "Hello World!"
然而,en dash的八进制表示形式超过三位数字(为20023
),因此您不能对此字符使用八进制表示法.
使用Unicode
您可以如下判断其Unicode representation:
as.hexmode(utf8ToInt("–"))
# [1] "2013"
R以以下格式取Unicode escape sequences:
具有给定代码的"\unnnn
"Unicode字符(1--4个十六进制数字)
具有给定代码的"\Unnnnnnnn
"Unicode字符(1--8个十六进制数字)
在这种情况下,您可以使用其中之一,但我倾向于使用大写变体,因为我不需要担心数字的数量.只需将其提供给sub()
:
sub("\U2013", "to", x = "–")
# [1] "to"