Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with substr

    Hello,

    I have a problem with the substr command.
    I want to extract the title from a file name that looks like this


    B09520003465-this is the title.csv

    I use the following code
    Code:
     gen title= substr(filename, 14, length(filename) - 4)

    and I get this


    this is the title.csv

    What am I missing?


    Thanks,

    Ylenia

  • #2
    The last argument of substr is the number of characters to retain, not some endpoint. As a result, you still need to subtract the initial 13 characters from the length to get what you want

    Code:
    gen title = substr(filename, 14, length(filename) -13 - 4)

    Comment


    • #3
      Nevermind, I misread the question.
      Last edited by Jorrit Gosens; 16 Jul 2018, 08:17.

      Comment


      • #4
        Got it,

        Thank you Jesse!

        Comment


        • #5
          Note that substr() is a function, not a command. In Stata the two are disjoint.

          Comment

          Working...
          X