0

Im trying to obtain the Unicode(code) of a character in VTL. For example I would like to get the number 902 from the character Ά The analogue in JS would be:

'Ά'.charCodeAt(0)

902

Similarly the char code of a blank space would be 32:

' '.charCodeAt(0)

32

Hairi
  • 3,318
  • 2
  • 29
  • 68

1 Answers1

0

What you need is the Character.codePointAt(str, index) static method.

#macro(unicode, $chr)
  #set($str = "$chr")
  $str.charAt(0).codePointAt($str, 0)
#end

#unicode('Ά')

Explanation: in VTL we need (dummy) instances to call static methods. We first convert the argument to a string and call charAt(0) on it to get a Character instance, just to be able to call the codePointAt() static method on its first character.

This seems rather convoluted, alas the Java API is not so great here.

Claude Brisson
  • 4,085
  • 1
  • 22
  • 30