Splitting a file name into name,extension

前端 未结 3 1079
南笙
南笙 2020-11-29 04:32

I have the name of a file like this: name1.csv and I would like to extract two substrings of this string. One that stores the name1 in one variable

3条回答
  •  孤独总比滥情好
    2020-11-29 05:03

    Use strsplit():

    http://stat.ethz.ch/R-manual/R-devel/library/base/html/strsplit.html

    Example:

    > strsplit('name1.csv', '[.]')[[1]]
    [1] "name1" "csv"  
    

    Note that second argument is a regular expression, that's why you can't just pass single dot (it will be interpreted as "any character").

提交回复
热议问题