【问题标题】:How to copy and paste a string with imbalanced quotation marks?如何复制和粘贴带有不平衡引号的字符串?
【发布时间】:2018-07-05 23:08:44
【问题描述】:

考虑以下文本

今天是“堆栈溢出”将无法实现其年度目标的那一天

如果我复制并粘贴此文本并尝试将其放入变量中,如下所示:

mystring = "Today is the day "Stack Overflow" will miss its year's target"

这不起作用,因为引号不平衡。

有简单的解决方案吗?如何将此文本复制并粘贴到我的 R 脚本中?

【问题讨论】:

  • 对不起,我错过了你有 year's 的报价。
  • 也许你不应该手动复制它,而是用rvest 抓取网页。
  • 您是手动复制粘贴吗?如果是这样,您可以找到 + 将 (") 替换为 (\")。
  • 试试readClipboard()或将其粘贴到一个文本文件中然后试试readLines()
  • 我建议不要使用 readClipboard - 您不希望每次运行时代码的结果都依赖于您的操作系统状态。如果您有大量文本,则文本文件方法可能是最好的。

标签: r string quotes double-quotes


【解决方案1】:

发短信给警察y

Today is the day "Stack Overflow" will miss its year's target.
Yesterday is the day "Stack Overflow" will miss its year's target's sum.

读入 R

x = readLines("clipboard")
#Warning message:
#In readLines("clipboard") : incomplete final line found on 'clipboard'

转换为data.frame

data.frame(x)                                                                             
#                                                                        x
#1           Today is the day "Stack Overflow" will miss its year's target.
#2 Yesterday is the day "Stack Overflow" will miss its year's target's sum.

除了"clipboard",您还可以将复制的文本粘贴到文件中并使用readLines

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    • 2018-05-31
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    相关资源
    最近更新 更多