用gsub R [duplicate]替换“ \”字符

问题描述 投票:0回答:1

有人知道我该如何替换r中的“ \”?

其他答案发表了类似的内容:

l <- "1120190\neconomic"
gsub("\\", "", l, fixed=TRUE)

但在我的情况下不起作用。

r regex gsub
1个回答
0
投票

您需要转义反斜杠,并在fixed=TRUE中使用gsub

s <- "first \\ second \\ third \\ multiple of them \\\\\\\\ \\ \\"
gsub("\\", "!", s, fixed=TRUE)
[1] "first ! second ! third ! multiple of them !!!! ! !"
© www.soinside.com 2019 - 2024. All rights reserved.