美文网首页
按小数点(英文句号)"."(dot)分割字符串

按小数点(英文句号)"."(dot)分割字符串

作者: 倪桦 | 来源:发表于2022-05-20 14:24 被阅读0次

    点号作为分隔符推荐转义处理 "\."

    string="head.body.tail"
    > stringr::str_split(string = string,pattern = "\\.",simplify = T)[,1]
    [1] "head"
    > stringr::str_split(string = string,pattern = "\\.",simplify = T)[,2]
    [1] "body"
    > stringr::str_split(string = string,pattern = "\\.",simplify = T)[,3]
    [1] "tail"
    

    也可以使用字符类"[.]"

    > stringr::str_split(string = string,pattern = "[.]",simplify = T)
         [,1]   [,2]   [,3]  
    [1,] "head" "body" "tail"
    

    相关文章

      网友评论

          本文标题:按小数点(英文句号)"."(dot)分割字符串

          本文链接:https://www.haomeiwen.com/subject/gbonurtx.html