remove all delimiters at beginning and end of string
<p>After I collapse my rows and separate using a semicolon, I'd like to delete the semicolons at the front and back of my string.  Multiple semicolons represent blanks in a cell.  For example an observation may look as follows after the collapse:</p>

<pre><code>;TX;PA;CA;;;;;;;
</code></pre>

<p>I'd like the cell to look like this:</p>

<pre><code>TX;PA;CA
</code></pre>

<p>Here is my collapse code:</p>

<pre><code>new_df &lt;- group_by(old_df, unique_id) %&gt;% summarize_each(funs(paste(., collapse = ';')))
</code></pre>

<p>If I try to gsub for semicolon it removes all of them.  If if I remove the end character it just removes one of the semicolons.  Any ideas on how to remove all at the beginning and end, but leaving the ones in between the observations?  Thanks.</p>