I was trying to get the length of "prüfen" in velocity.
Example:
#set ($data = "prüfen")
#set( $total_length = $data.length())
$total_length // Output is 6
Question : I want output as 7 (as character "ü" occupies size of 2) How to get the length of "prüfen" in velocity.
I have also tried with
#set( $len_of_data = $data.getBytes().length)
$len_of_data
But nothing is working.
This seems to work:
#set ($data = "prüfen")
#set( $total_length = $data.getBytes('UTF-8').size())
$total_length
Be sure to configure Velocity with input.encoding = UTF-8.
With Velocity 1.7+, you can call size() on an array as if it was a list (as well as isEmpty() and get(int)).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With