Remove suffix question

Hi,
i am using the remove suffix operator to remove a trailing “1” in a custom field . now what i have noticed is that the “1” gets removed on first attempt , however if i hit the button again the entire contents of the the custom field are removed. and the operator ignores the criteria i put, and wipes the entire field .

what could i be doing wrong ?

<$button>trim
<$action-setfield $tiddler=<<currentTiddler>> $field=myfield $value={{{ [<currentTiddler>get[myfield]removesuffix[1]] }}}/>
</$button>

The removesuffix[] operator filters out titles that don’t have the specified suffix. See https://tiddlywiki.com/#removesuffix%20Operator

Try this instead:


<$button>trim
<$action-setfield $tiddler=<<currentTiddler>> $field=myfield $value={{{ [<currentTiddler>get[myfield]trim:suffix[1]] }}}/>
</$button>
1 Like

Thanks Saqimtiaz,

This works ,but actually i didn’t explain myself well

ok , so the field does not only contain only “1” but other characters as well.

so the field would be like XYZ1111

and the requirement is to remove only one instance of “1” with every click ,and after 4 clicks you would be left with XYZ, and if you click the button again nothing happens, so the button wouldn’t work afterwards , remove suffix seemed to work but it wont stop and will continue to remove XYZ .

i hope this makes sense and sorry for the confusion

Try using:

$value={{{ [<currentTiddler>get[myfield]removesuffix[1]] ~[<currentTiddler>get[myfield]] }}}

This will progressively remove just a single trailing “1” each time the button is pressed. When there is no trailing “1”, the first filter run will result in an empty list (as you’ve already noted), which triggers the second “else” filter run to be applied, setting the field value to it’s current value (so “nothing” happens) and the remaining field contents are retained.

enjoy,
-e

1 Like

Thank you eric:) ,one more question , may i ask what is the purpose of the Tilde, cause i often see it between filter runs in other people code, but have never understood what it actually does

thanks again

~ isa the same as and :else filter run, basically if the earlier part gives no result it will do that instead.

Sadly it is not clear when you search for else because the else operator comes up instead, see here in Filter Expression and you can search for single characters like ~

  • If you remember is is also a filter run you can search for :else
1 Like

Thanks tones Eric and Saqimtiaz for all your help :slight_smile:

The tilde is the abbreviated form of the :else[...] filter run prefix. It basically says, “if the preceding filter run(s) don’t produce any results, then apply this filter run.”

Note that there are several filter run prefixes that have abbreviated forms (which were the original prefixes before “named prefixes” were added in v5.1.23)
= (:all) - prevents de-duplication of filter runs
+ (:and) - applies filter run to preceding filter results
- (:except) - removes filter run results from preceding filter results
~ (:else) - applies filter run if preceding filter results are empty

-e

2 Likes