Search code examples
whitespacevelocity

Velocity - Checking for whitespaces in a string and return those strings


We often have the situation, that string values start with a whitespace. How can I check and return all strings which start with a whitespace?

I found a similar question: Velocity, what's the most efficient way to check if a string is empty and not null

But I don't know how to exactly do it, as I have never done anything with Velocity before.


Solution

  • Don't forget that you can call Java methods on Velocity references. So nothing stops you from doing:

    #foreach($str in $myStrings)
      #if($str.startsWith(' '))
        ## do something with $str
      #end
    #end