Remove everything after space in string

前端 未结 4 506
后悔当初
后悔当初 2020-11-30 12:20

I would like to remove everything after a space in a string.

For example:

\"my string is sad\"

should return

\"m         


        
4条回答
  •  抹茶落季
    2020-11-30 13:05

    or, substitute everything behind the first space to nothing:

    gsub(' [A-z ]*', '' , 'my string is sad')
    

    And with numbers:

    gsub('([0-9]+) .*', '\\1', c('c123123123 0320.1'))
    

提交回复
热议问题