Remove everything after space in string

前端 未结 4 510
后悔当初
后悔当初 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:11

    If you want to do it with a regex:

    gsub('([A-z]+) .*', '\\1', 'my string is sad')
    

提交回复
热议问题