简体   繁体   中英

How can I convert a given ASCII value to corresponding character in Velocity Template?

I want to convert a given ASCII value to the corresponding character in a FOP template using velocity.

For Eg: I want ASCII value of 65 to get converted to A

I have tried putting a Character Object in the velocity context and then used Character.toChars(int) but velocity printed its address instead of the the corresponding character, can somebody tell me what I am doing wrong. Or is there a better way to do it.

In velocity context:
VelocityContext.put("char", new Character());

In FOP Template
set($asciiValue = 65)
$char.toChars($asciiValue)

You can pass your custom converter to Velocity context (as you pass Character object). But also you can change your code to this:

#set ($string = " ")
#set ($asciiValue = 65)
#set ($chars = $char.toChars($asciiValue))
#set ($letter = $string.copyValueOf($chars)) 
$letter

copyValueOf is used for create String from char array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM