removing everything after first 'backslash' in a string

前端 未结 3 1366
无人及你
无人及你 2020-12-19 22:45

I have a vector like below

vec <- c(\"abc\\edw\\www\", \"nmn\\ggg\", \"rer\\qqq\\fdf\"......)

I want to remove everything after as soon

相关标签:
3条回答
  • 2020-12-19 22:46

    another solution :

     sub("\\\\.*", "", x)
    
    0 讨论(0)
  • 2020-12-19 23:02
    vec <- c("abc\\edw\\www", "nmn\\ggg", "rer\\qqq\\fdf")
    sub("([^\\\\])\\\\.*","\\1", vec)
    [1] "abc" "nmn" "rer"
    
    0 讨论(0)
  • 2020-12-19 23:10

    strssplit(vec, "\\\\") should do the job.

    TO select the first element [[1]][1] 2nd [[1]][2]

    0 讨论(0)
提交回复
热议问题