How to get the number of occurrences of characters in a string?
\documentclass[14pt]{extarticle}
\usepackage{xstring}
\usepackage{forloop}
\usepackage{ifthen}
\usepackage{pgfkeys}
\newcommand{\fios}{hellow world}
\begin{document}
%\StrCount{\fios}{e}
%\StrChar{\fios}{1}
\StrLen{\fios}[\varL]
\varL
\vspace{5ex}
\newcounter{loop}
\forloop{loop}{1}{\value{loop}< \varL}
{\StrChar{\fios}{\arabic{loop}}~--
\par
}
\end{document}
I need to get:
h - 1
e - 1
l - 3
o - 2
w - 2
r - 1
d - 1
Best Answer
This is a Lua snippet with some CJKV characters in the strings. I've selected an opentype font from TeX Live, but it doesn't contain some diacritical letters (e.g. č, ř and š), let me hope it is sufficient as a demonstration of handling UTF-8 strings. We run
lualatex mal-letters.tex
.In the terminal, we will spot a similar structure to this one: