R替换单反斜杠以加倍反斜杠

时间:2017-03-05 10:05:53

标签: r backslash

如何在R

中将单反斜杠\转换为双反斜杠\\

例如:

\\\server\\folder1\\sub_folder -> "\\\\\\\server\\\\folder1\\\\sub_folder"

1 个答案:

答案 0 :(得分:1)

# What your input should look like.
txt <- "\\\\server\\folder1\\sub_folder"
cat(txt) # prints \\server\folder1\sub_folder

# Replacing the backslashes for double backslashes.
txtNew <- gsub("\\", "\\\\", txt, fixed = TRUE)
cat(txtNew) # prints \\\\server\\folder1\\sub_folder