You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Apache Velocity(VTL)中获取字符的Unicode编码

在VTL中获取字符的Unicode编码

要在VTL中获取字符的Unicode编码,直接借助Java字符串的原生方法即可实现,因为Velocity模板支持调用Java API。

示例1:获取字符Ά的Unicode编码

VTL写法如下:

#set($targetChar = 'Ά')
#set($unicodeCode = $targetChar.codePointAt(0))
$unicodeCode

执行后输出结果:

902

示例2:获取空格的Unicode编码

用同样方式处理空格:

#set($spaceChar = ' ')
#set($spaceUnicode = $spaceChar.codePointAt(0))
$spaceUnicode

执行后输出结果:

32

另外也可以通过charAt(0)结合类型转换实现,效果一致:

#set($unicodeCode = $targetChar.charAt(0).intValue())

内容的提问来源于stack exchange,提问作者Hairi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 06:50:17