Werner's answer answers the question as stated, and I'm not suggesting you unaccept it, but as clarified in comments the actual aim was to check that an input argument has more than (say) 3 characters. That is much simpler and doesn't involve counting anything.
To give an example, the following document shows a direct test that the fourth position is not empty followed by the test using xstring
.
In both cases the tests show N
for ab
and Y
for abcd
but defining the test and executing the two tests one way takes 70 lines of log file, doing it the other way takes 2360 lines of log output. \tracingall
output is usually a fair indication of actual TeX speed, and it's an interesting read anyway to see what TeX is doing behind the scenes.
\documentclass{article}
\tracingall
% check at least four characters
\makeatletter
\def\strcheck#1{\xstrcheck#1{}{}{}{}\xstrcheck}
\def\xstrcheck#1#2#3#4#5\xstrcheck{%
\ifx\valign#3\valign
\expandafter\@secondoftwo
\else
\expandafter\@firstoftwo
\fi}
\strcheck{ab}{\show Y}{\show N}
\strcheck{abcd}{\show Y}{\show N}
\makeatother
\usepackage{xstring,xifthen}
\def\strcheckb#1{%
\StrLen{#1}[\mystringlen]%
\ifthenelse{\mystringlen > 3}}
\strcheckb{ab}{\show Y}{\show N}
\strcheckb{abcd}{\show Y}{\show N}
\stop
\mythresh
would be a length like1cm
) or do you mean number of characters (so\mythresh
would be a number like 3) In the latter case what is the length of\'{e}\textcolor{red}{f}z
? Typeset length is the easiest to measure (or define)\'{e}\textcolor{red}{f}z
(There are several possible answers, some of which are easier to code than others) It can't happen, all input is ascii text with no markup would be one answer....\ifx\valign#1\valign
which will test that#1
is empty (as long as it isn't\valign
) in a single expansion step.