'How to split string in chars and get code of each char in freemarker?

I think that I can split using this:

<#list str as c>
    ...
</#list>

But then I need to convert this char to byte and add it to another number. In most languages it will be like so:

int num=53, res;
char c='g';
res=num+c;//c cast to byte and then to int.

But I have no idea, how to do this.

P.S. I can't modify code, I only can add html pages, so I have to use freemarker for my logic.



Solution 1:[1]

You can't add numbers to characters in FreeMarker out-of-the-box. The closest thing is num?lower_abc (and n?upper_abc), which converts 1 to 'a', 2 to 'b', and so on. If you can't solve the task with that, and you can't add Java classes either, then this is going to be problem...

Also, you can't #list a string like that, but like this:

<#list 0..<str?length as i>
    <#assign c = str[i]>
    ...
</#list>`.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ddekany