Trim only trailing whitespace from end of string in Swift 3 : <p>Every example of trimming strings in Swift remove both leading and trailing whitespace, but how can <em>only trailing</em> whitespace be removed?</p>

<p>For example, if I have a string:</p>

<pre><code>"    example  "
</code></pre>

<p>How can I end up with:</p>

<pre><code>"    example"
</code></pre>

<p>Every solution I've found shows <code>trimmingCharacters(in: CharacterSet.whitespaces)</code>, but I want to retain the leading whitespace.  </p>

<p>RegEx is a possibility, or a range can be derived to determine index of characters to remove, but I can't seem to find an elegant solution for this.</p>
