string - 删除标点符号但保留表情符号?

标签 string r text gsub emoticons

是否可以删除所有标点符号但保留表情符号,例如

:-(

:)

:D

:p

structure(list(text = structure(c(4L, 6L, 1L, 2L, 5L, 3L), .Label =     c("ãããæããããéãããæãããInappropriate announce:-(", 
"@AirAsia your direct debit (Maybank) payment gateways is not working. Is it something     you are working to fix?", 
"@AirAsia Apart from the slight delay and shortage of food on our way back from Phuket, both flights were very smooth. Kudos :)", 
"RT @AirAsia: ØØÙØÙÙÙÙ ÙØØØ ØØØÙ ÙØØØØÙ ØØØØÙÙÙí í Now you can enjoy a #great :D breakfast onboard with our new breakfast meals! :D", 
"xdek ke flight @AirAsia Malaysia to LA... hahah..:p bagi la promo murah2 sikit, kompom aku beli...", 
"You know there is a problem when customer service asks you to wait for 103 minutes and your no is 42 in the queue. X-("
), class = "factor"), created = structure(c(5L, 4L, 4L, 3L, 2L, 
1L), .Label = c("1/2/2014 16:14", "1/2/2014 17:00", "3/2/2014 0:54", 
"3/2/2014 0:58", "3/2/2014 1:28"), class = "factor")), .Names = c("text", 
"created"), class = "data.frame", row.names = c(NA, -6L))

最佳答案

我将此功能添加到 qdap version > 2.0.0作为 sub_holder功能。基本上这个函数使用 the response I gave above但减轻了编码负担。 sub_holder函数接受一个文本向量和您想要分出的项目(例如表情符号)。它返回一个列表:

  • 测试的向量,其中项目被替换为占位符
  • 一个函数(称为 unhold )将持有人交换为原始条款

  • 这是代码:
    emos <- c(":-(", ":)", ":D", ":p", "X-(")
    (m <- sub_holder(emos, dat[,1]))
    m$unhold(strip(m$output, digit.remove = FALSE, lower.case=FALSE, char.keep=c("!", "?")))
    

    关于string - 删除标点符号但保留表情符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23447261/

    相关文章:

    SQL:查找行之间最长的公共(public)字符串

    写入 char const* 时编译器抛出 "Invalid initializer"

    php - 如何读取文本并获取字符串以转换JSON文件php

    text - 准确的文本生成

    R:将数据框中的文本(字符)转换为整数类型

    Python:千位分隔符 - 旧格式语法

    C++,使用自己的条件在文件中搜索字符串

    r - httr::POST() 的 "body"参数中的 JSON 数组

    r - 查找 r 中多列与一列的聚合相关性

    r - 如何仅沿 ggplot2 图的一侧添加边框?