title: Strsplit() by second occurence of the delimiter
body: <p>I am trying to split by the second occurrence of a character in a string (return substring in string before second appearance of character <code>x</code>) </p>
  
  <p>For the string: </p>
  
  <p><code>s &lt;-"a_b_c"</code> , if delimiter is <code>"_"</code> , I need  the substring : <code>"a_b"</code> </p>
  
  <p>My function returns the substring by first occurence:</p>
  
  <pre><code> return_topic&lt;-function(s)
   {
     if (length(grep("_",s))&gt;0)
       { return (unlist(strsplit(s,"_"))[1])}
      else return  (" ")
  
    }
  
  
  &gt; return_topic("a_b_c")
  [1] "a"
  </code></pre>