1
> name = '645te5.78d'

我正在寻找一个可以摆脱我的变量中的点和任何内容的函数name

> new_fun(name)
> name
'645te5'
4

2 回答 2

3

sub should work:

sub('\\..*', '', name)
于 2013-11-03T18:36:15.277 回答
2

If that is a general case that

There exist only one dot and you want to get the first part. Maybe you strsplit instead.

unlist(strsplit(name, '\\.'))[1]
于 2013-11-03T18:36:29.870 回答