#2297 How about... Str? Str.trimToNull()

SlimerDude Fri 6 Jun 2014

Another little thing I often miss (from Java land) is the ability to trim a Str to null. It works just like Str.trim() but goes one step further and returns null should the result be empty.

I miss this because, despite being trivial, it breaks the flow of the code:

data := myStr.trimToNull

vs

data := (Str?) myStr.trim
if (data.isEmpty)
  data = null

I usually end up writing a method just so I can inline it:

data := trimToNull(myStr)

Str? trimToNull(Str str) { ...

andy Mon 9 Jun 2014

I have used this pattern some - so this could be useful. Not sure I like that name though, but don't have any better suggestions at the moment.

brian Mon 9 Jun 2014

I like that, and think trimToNull is decent name. Steve do you want to email me a patch (we should implementation for both Java and JS, plus test in testSys::StrTest)

SlimerDude Wed 11 Jun 2014

Okay, will do.

Login or Signup to reply.