-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,381
  • 37
  • 106
  • 126
xirururu
  • 4,468
  • 8
  • 30
  • 57
  • 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,365
  • 5
  • 22
  • 28