The title of this question refers to words in a general sense but in my particular case I'm searching for numbers inside a previously defined macro. In that macro I have only numbers separated by spaces. I would like to search inside \teststr
for a number stored in a counter, e.g.:
\newcounter{testx}
\newcounter{testy}
\def\teststr{ 1 2 3 4 5 9 10 11 30 }
\ExplSyntaxOn
\cs_generate_variant:Nn \seq_set_split:Nnn {NVV}
\cs_new:Npn \test #1#2#3{
\int_set_eq:NN \l_tmpa_int {#2}
\seq_set_split:NVV \l_tmpa_seq \l_tmpa_int {#1}
\int_set:cn {c@#3} {(\seq_count:N \l_tmpa_seq) -1}}
\ExplSyntaxOff
The \test
macro should be invoked the following way:
\test{\teststr}{\value{testx}}{testy}
In the following example, the counter testy
stores the number 1
. That's the expected behavior.
\setcounter{testx}{4}
\test{\teststr}{\value{testx}}{testy}
Now, testy
should contains 0
as its value. Also it works:
\setcounter{testx}{6}
\test{\teststr}{\value{testx}}{testy}
But with 1
doesn't behaves as I would wish:
\setcounter{testx}{1}
\test{\teststr}{\value{testx}}{testy}
it stores 4
because \teststr
contains four occurrences of 1
, that's right but I would like to search like searching 'words', i.e. with spaces before and after the search pattern.
I did test with _tl
and _str
variable types on second arg of \seq_set_split
without success.
Any help would be appreaciated. Thanks in advance.
1 2 1 2 3 2 4
, looking for1
should return 2 and looking for2
should return 3?