zoukankan      html  css  js  c++  java
  • 【R语言】常用的字符串处理函数 【待更新】

    1.

    #字符串连接:
    paste() #paste(..., sep = " ", collapse = NULL)

    #字符串分割:
    strsplit() #strsplit(x, split, extended = TRUE, fixed = FALSE, perl = FALSE)

    例如.

    strsplit('123abcdefgabcdef','ab')
    [[1]]
    [1"123"   "cdefg" "cdef" 


    #计算字符串的字符数:
    nchar()

    #字符串截取:
    substr(xstartstop)
    substring(textfirstlast = 1000000)
    substr(xstartstop) <- value
    substring(textfirstlast = 1000000) <- value

    #字符串替换及大小写转换:
    chartr(oldnewx)
    tolower(x)
    toupper(x)
    casefold(xupper = FALSE

    #匹配相关的函数:

    字符完全匹配
    grep()
    字符不完全匹配
    agrep()
    字符替换
    gsub()
    #以上这些函数均可以通过perl=TRUE来使用正则表达式。
         grep(patternxignore.case = FALSEextended = TRUE,
              perl = FALSEvalue = FALSEfixed = FALSEuseBytes = FALSE)

         sub(patternreplacementx,
             ignore.case = FALSEextended = TRUEperl = FALSE,
             fixed = FALSEuseBytes = FALSE)

         gsub(patternreplacementx,
              ignore.case = FALSEextended = TRUEperl = FALSE,
              fixed = FALSEuseBytes = FALSE)

         regexpr(patterntextignore.case = FALSEextended = TRUE,
                 perl = FALSEfixed = FALSEuseBytes = FALSE)

         gregexpr(patterntextignore.case = FALSEextended = TRUE,
                  perl = FALSEfixed = FALSEuseBytes = FALSE)
    See Also:

         regular expression (aka 'regexp'for the details of the pattern
         specification.

         'glob2rx' to turn wildcard matches into regular expressions.

         'agrep' for approximate matching.

         'tolower''toupper' and 'chartr' for character translations.
         'charmatch''pmatch''match'. 'apropos' uses regexps and has
         nice examples.

  • 相关阅读:
    socket编程技巧(2)发送缓冲区和接收缓冲区的设置时机
    socket编程技巧(1)tcp接收接口(变长数据定长数据)的编写实例
    libnet介绍与分析
    TCP的6大标示符号
    数据帧中常见协议类型
    C语言中offsetof宏的应用
    ip欺骗(原始套接字系列九)
    ARP欺骗(原始套接字系列八)
    包分析(原始套接字七)
    了解Javascript中函数作为对象的魅力
  • 原文地址:https://www.cnblogs.com/xianghang123/p/2597746.html
Copyright © 2011-2022 走看看