velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apa...@recks.org
Subject Re: How can I trimming $string ?
Date Fri, 19 May 2006 07:17:00 GMT
Hi,

this is a typical whitespace issue. Please note that
Velocity mostly leaves the whitespaces you coded in
your template. Many times it would be desirable to
be able to add indented markup without introducing
spacing and formatting artifacts. This issue is
under discussion in the wiki page:
   http://wiki.apache.org/jakarta-velocity/VelocityWhitespaceGobbling

In your specific case the proposed solutions will not
have any impact on your code. You have clearly included
two spaces and an EOL symbol. If you do not want these,
you have to encapsule these formatting artifacts within
comments:
#macro( returnString $arg )#*
   *#...do something#*
   *#$returnVal##
#end

With the http://wiki.apache.org/jakarta-velocity/VelocityWhitespaceGobbleStructuredTemplates
approach it would only need a markup addition to indicate
that surrounding whitespaces are not desired (this is *not*
implemented yet):
#macro( returnString $arg )
   ...do something
   #text( $returnVal )
#end

Hope this clarifies your issue,
Christoph

trad-ex wrote:
> Hi all,
> 
> I have a question how to trim string smarter way.
> My code is:
> 
> #macro( returnString $arg )
>   ...do something
>   $returnVal
> #end
> 
> ....
> 
>   #set( $somVal = "#returnString( $arg )" )
>   
> When I checked the contents of $someVal, it contained two leading space-
> charachters and trailing \r\n.
> So I should use trim() before I use $someVal value.
> For instances,
> 
>  #if( $someVal.trim() == "SomeThing" )
>  
> My question is:
> 1. Is there smarter way to trim the white-spaces ?
> 2. What's wrong with my codes ?
> 
> Best Regards,
> trad-ex
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message