You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by chenjian <ch...@uvic.ca> on 2004/05/31 01:51:10 UTC
invoking method with primitive char type
Hi,
I want to invoke a method with primitive char type from the velocity template,
but could not get it work. Here is the stuff I want to do:
In the template, $util.remove($xxx, ' '), where $xxx is a String and this
method removes white space characters.
In the util class, I have:
public String WebUtil(String inStr, Character c){
// do remove c from inStr
}
I searched google as well as velocity mailing list but could not find a clue
about char primitive type. Any help is really appreciated!
Thanks,
Jian
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: invoking method with primitive char type
Posted by Nathan Bubna <na...@esha.com>.
chenjian said:
> I want to invoke a method with primitive char type from the velocity
template,
> but could not get it work. Here is the stuff I want to do:
>
> In the template, $util.remove($xxx, ' '), where $xxx is a String and this
> method removes white space characters.
>
> In the util class, I have:
> public String WebUtil(String inStr, Character c){
> // do remove c from inStr
> }
as Nathan Green pointed out, Velocity creates a String when using single
quotes, not a character. and being a template language, there isn't any way
to directly create primitive chars. if you can't just change your method to
take a String for the second argument, then you might try:
<untested suggestion>
#set( $spaceString = ' ' )
$util.remove( $xxx, $spaceString.charAt(0) )
</untested suggestion>
Nathan Bubna
nathan@esha.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: invoking method with primitive char type
Posted by Nathan Green <ng...@inco5.com>.
Obviously I didn't finish reading your message... Sorry about that.
How about this?:
public String WebUtil(String inStr, String chars) {
for (int i=0; i<chars.length(); i++)
inStr = WebUtil(inStr, chars.charAt(i));
return inStr;
}
Caveat: I haven't tested this code, so verify for yourself that it's not
full of bugs. It might be more efficient to use a StringBuffer, but you
are the one to make that call.
Nathan
chenjian wrote:
> Hi,
>
> I want to invoke a method with primitive char type from the velocity template,
> but could not get it work. Here is the stuff I want to do:
>
> In the template, $util.remove($xxx, ' '), where $xxx is a String and this
> method removes white space characters.
>
> In the util class, I have:
> public String WebUtil(String inStr, Character c){
> // do remove c from inStr
> }
>
> I searched google as well as velocity mailing list but could not find a clue
> about char primitive type. Any help is really appreciated!
>
> Thanks,
>
> Jian
>
>
>
> ---------------------------------------------------------------------
> 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
Re: invoking method with primitive char type
Posted by Nathan Green <ng...@inco5.com>.
Not sure how Velocity handles primitives, but '' indicates a non-parsed
String. Here's a couple references:
http://jakarta.apache.org/velocity/user-guide.html#String%20Literals
http://jakarta.apache.org/velocity/vtl-reference-guide.html
You might search the list archives, I'm sure this has come up before.
Nathan
chenjian wrote:
> Hi,
>
> I want to invoke a method with primitive char type from the velocity template,
> but could not get it work. Here is the stuff I want to do:
>
> In the template, $util.remove($xxx, ' '), where $xxx is a String and this
> method removes white space characters.
>
> In the util class, I have:
> public String WebUtil(String inStr, Character c){
> // do remove c from inStr
> }
>
> I searched google as well as velocity mailing list but could not find a clue
> about char primitive type. Any help is really appreciated!
>
> Thanks,
>
> Jian
>
>
>
> ---------------------------------------------------------------------
> 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