【发布时间】:2017-01-02 00:13:18
【问题描述】:
我需要转义文本字符串以将它们插入 SQLite 数据库。
问题出在我的管道中,我可能已经转义了字符串。我需要注意'' 的可能性。
例如,
string1 <- "On the Internet, nobody knows I'm a dog"
string2 <- "On the Internet, nobody knows I''m a dog"
gsub("'", "''", string1)
# [1] "On the Internet, nobody knows I''m a dog"
但是
gsub("'", "''", string2)
# [1] "On the Internet, nobody knows I''''m a dog"
还有
gsub("([^'])'[^']", "'", string2)
# "On the Internet, nobody knows I''m a dog"
但是
gsub("([^'])'[^']", "'", string1)
# [1] "On the Internet, nobody knows ' a dog"
【问题讨论】:
-
@hrbrmstr 其实我没有。
-
这是一个混乱的业务,您可以通过使用
RODBCext包的参数化查询来避免。