title: stata: remove everything after the last occurrence of a specified character
body: <p>My data is like this</p>
  
  <p>Var<br>
  A (c) | B(/ c/) | C.c<br>
  F | G9<br>
  K | S | V | S<br>
  F | A </p>
  
  <p>I want to get everything before the last occurrence of the character "|" in Stata, like follows:  </p>
  
  <p>NewVar<br>
  Var<br>
  A (c) | B(/ c/) |<br>
  F |<br>
  K | S | V |<br>
  F |      </p>
  
  <pre><code>egen NewVar=ends(Var), punct(|) last trim   
  </code></pre>
  
  <p>can give me everything after the last occurrence of the character "|". But I have not found a way to get everything before the last occurrence of a character. Thank you!</p>