I need to determine the number of printed characters from a multi-byte string. Further, the strings are passed to the routine via \def (ultimately via the readarray process to input a csv file).
I am using the code from Multibyte StrLen? (StrLen for chinese characters) as the packages (xstring and stringstrings) don't handle multi-byte characters.
I have simplified the example as a minimal code
\documentclass[a4paper,11pt]{article}
% Attempt to get the length of a utf8 multi byte string
% Only works when supplied with the string directly
% does not work with \def strings
%
% https://tex.stackexchange.com/questions/419215/multibyte-strlen-strlen-for-chinese-characters
%
\def\zz#1{\edef\theresult{\zzz0#1\relax}}
\def\zzz#1#2{%
\ifx\relax#2 \the\numexpr#1\relax
\else
\expandafter\zzz\expandafter{%
\the\numexpr(#1+\ifnum\expandafter`\string#2<"80 1\else \ifnum\expandafter`\string#2>"BF 1 \else 0 \fi\fi
\expandafter)\expandafter\relax\expandafter}%
\fi}%
\begin{document}
\def\v1{abc}
\v1 \zz{abc} \theresult\\ %this works
\zz{\v1} \theresult\\ %this doesn't work Error: Missing = inserted for \ifnum.
\end{document}