2017-03-05 107 views
-1

如何從單一的反斜槓「\」,以R中R替換單反斜線雙反斜線

雙反斜線「\\」例如轉換: \\服務器\文件夾1 \ sub_folder - >「\\\\ server \\ folder1 \\ sub_folder「

+0

字符串變量中的反斜槓?還是他們坐在你的文本編輯器/控制檯?你想做什麼? –

+0

用戶在R閃亮文本區域輸入一個輸入如下:\\ folder1 \ subfolder1 \ werwr,並且我想將每個\更改爲\\ –

回答

0
# 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