07-19-2023, 12:26 AM
In Python, we can use the [`.strip()`][1] method of a string to remove leading or trailing occurrences of chosen characters:
<pre><code>>>> <b>print " (Removes (only) leading & trailing brackets & ws ) ".strip(" ()")</b>
'Removes (only) leading & trailing brackets & ws'</code></pre>
How do we do this in Ruby? Ruby's [`strip`][2] method takes no arguments and strips only whitespace.
[1]:
<pre><code>>>> <b>print " (Removes (only) leading & trailing brackets & ws ) ".strip(" ()")</b>
'Removes (only) leading & trailing brackets & ws'</code></pre>
How do we do this in Ruby? Ruby's [`strip`][2] method takes no arguments and strips only whitespace.
[1]:
[To see links please register here]
[2]:[To see links please register here]