-1

I have a string "00_123.txt". I want to get first part of the string before ".", that is simply "00_123"

I found the substring("00_123.txt", 0, stop) can do it. But the problem is that I don't know where to stop, because the length of "00_123" can be changed.

How can I do that?

Undo
  • 25,519
  • 37
  • 106
  • 129
xirururu
  • 5,028
  • 9
  • 35
  • 64
  • 1
    Did you search before asking this question? http://stackoverflow.com/search?q=get+first+part+of+a+string+in+R – thelatemail Aug 07 '15 at 03:04

1 Answers1

1
x <- "00_123.txt"
gsub("\\..*$", "", x)
[1] "00_123"
Whitebeard
  • 5,945
  • 5
  • 24
  • 31