You made an error in your macro, Jeremy. You should have used $arg$ instead
of <arg>.
Thus your code would be
\define count-words(title,word)
<$text text={{{ [[$title$]get[text]split[$word$]count[]subtract[1]] }}}/>
\end
But it is false nonetheless because it would, for example, cut word "totem"
if asked for word "to". My regular expression does not do that thanks to
the \b at both ends of the arguments.
Le jeudi 23 septembre 2021 à 16:45:46 UTC+2, [email protected] a écrit :
> Another technique is to use the “split” operator to split the string by
> the word:
>
> \define count-words(title,word)
> <$text text={{{ [<__title__>get[text]split<__word__>count[]subtract[1]]
> }}}/>
> \end
>
> <<count-words "HelloThere" "the">>
>
> Using the splitregexp operator instead allows would allow splitting case
> insensitively, which might be more useful.
>
> Best wishes
>
> Jeremy.
>
> On 23 Sep 2021, at 15:37, Jean-Pierre Rivière <[email protected]>
> wrote:
>
> Here it is.
>
> ```
> \define count-word(word, tid)
> {{{
> [[$tid$]get[text]search-replace:gi:regexp[\b$word$\b],[þ]dump:v[first]search-replace:g:regexp<but>,[]dump:v[final]length[]]
>
> }}}
> \end
>
> <<count-word foo "bar tiddler tittle">>
> ```
>
> I use a char that should never be within the tiddler, þ in my example. You
> can use another rare character is old English is concerned! I replace every
> occurrence of the word with it, then remove any other character then count
> the length of the result. If you want case sensitive search, just omit the
> `i` flag in the first `search-replace`.
>
> Le mercredi 22 septembre 2021 à 15:14:55 UTC+2, [email protected]
> a écrit :
>
>> Hi ,
>>
>> is there a way to count the number of occurrences of a specific word in a
>> tiddler
>>
>> I have serached , but could only find a plugin that counts the total
>> number of words, or total number characters.
>>
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "TiddlyWiki" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/tiddlywiki/a30f622a-627f-41a5-a532-4015e0f3faaen%40googlegroups.com
>
> <https://groups.google.com/d/msgid/tiddlywiki/a30f622a-627f-41a5-a532-4015e0f3faaen%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/ab5296b2-f778-4334-9eef-1892487d6f19n%40googlegroups.com.