Add left and right trim to String in Groovy
ouryperd
Posted on April 11, 2022
Left trim:
String.metaClass.ltrim = { return delegate.replaceAll(/^* /, '') }
Right trim:
String.metaClass.rtrim = { return delegate.replaceAll(/ *$/, '') }
Usage:
assert ' Groovy'.ltrim() == 'Groovy'
assert 'Groovy '.rtrim() == 'Groovy'
assert ' Groovy'.ltrim() == 'Groovy'
assert 'Groovy '.rtrim() == 'Groovy'
💖 💪 🙅 🚩
ouryperd
Posted on April 11, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
postmancli Automating API Testing with Postman CLI: Advanced Capabilities and New Alternatives
November 20, 2024
umbraco Catching the Bus? How a Service Bus and Azure Functions Can Help Your Integration Reliability
November 7, 2024