[英]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.我想使用速度将给定的 ASCII 值转换为 FOP 模板中的相应字符。
For Eg: I want ASCII value of 65 to get converted to A例如:我希望将 65 的 ASCII 值转换为 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.我试过在速度上下文中放置一个字符对象,然后使用 Character.toChars(int) 但速度打印了它的地址而不是相应的字符,有人可以告诉我我做错了什么。 Or is there a better way to do it.或者有没有更好的方法来做到这一点。
In velocity context:在速度上下文中:
VelocityContext.put("char", new Character());
In FOP Template在 FOP 模板中
set($asciiValue = 65)
$char.toChars($asciiValue)
You can pass your custom converter to Velocity context (as you pass Character object).您可以将自定义转换器传递给 Velocity 上下文(在传递 Character 对象时)。 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. copyValueOf
用于从字符数组创建字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.