Search code examples
m4

how to chop the last char of a string in m4


I am trying to create a macro for deleting the last char of a string in m4, I have trying to do something like:

define(`delete_last',substr(`$1',`0',eval(``len($1)'-1')))dnl

This is the one that has been closest to work, but still I cannot achieve it properly. I need some help now.


Solution

  • Don't know it this is the optimal way to do it, but it works:

    define(`__count_m1',`eval($1 - $2)')dnl
    define(`__del_last3',`substr($1,`0',__count_m1(len($1),3))')dnl