zoukankan      html  css  js  c++  java
  • R语言字符串函数

    字符串长度:

    nchar("hello world")

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

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

    aa<-unlist(strsplit(x, 'char'))

    aa[1] # first string



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

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

     substr("abcdef", 2, 4)
    [1] "bcd"

    > x <- "1234567890"
    > substr(x, 3, 3)
    [1] "3"
    > 
    > substr(x, 5, 7)
    [1] "567"
    > 
    > substr(x, 4, 4) <- "A"
    > x
    [1] "123A567890"
    > 
    > substr(x, 2, 4) <- "TTF"
    > x
    [1] "1TTF567890"
    > 
    > substr(x, 9, 12) <- "ABCD"
    > x
    [1] "1TTF5678AB"
    > 
    > substring(x, 5)
    [1] "5678AB"
    > 
    > substring(x, 5) <- "..."
    > x
    [1] "1TTF...8AB"




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

    x=gsub(old_strin, new_string, x) # replace string 字符串替换

    ## 包含子字符串: chars中是否包含value

    grepl(value, chars) # chars contains value? (TRUE, FALSE)

    #字符串比较:

    if(as.character(x)==as.character(y))


    判断字符串是否包含某个子串
    > chars <- "test"
    > value <- "es"
    > grepl(value, chars)
  • 相关阅读:
    支付宝支付
    String.Format()
    小偷网站工具--Teleport Ultra
    java元注解 @Retention注解使用
    java元注解 @Documented注解使用
    java元注解 @Target注解用法
    java注解 @SuppressWarnings注解用法
    阿里巴巴的全链路压测
    接口测试Case之面向页面对象编写规范
    压力测试性能问题分析
  • 原文地址:https://www.cnblogs.com/emanlee/p/3537876.html
Copyright © 2011-2022 走看看