Removing empty space between numbers with macro

147 views
Skip to first unread message

tobaisch

unread,
Jan 8, 2018, 6:16:26 PM1/8/18
to tiddl...@googlegroups.com
Hello,
Mark and Eric here from the forum helped me with a macro which adds the content of a field with id numbers to a ext. website link.
Sometimes the field content also has empty space between the numbers. for example. "22 33 44"
How can you complete the macro that removes this spaces?
Here is the macro:

\define mymacro2(web id) [ext[Linktext|$web$$id$]]
\define mymacro() <$macrocall $name="mymacro2" web="https://mydomain.com/files/" id={{!!webid}}/>

the webid is the field with the numbers
Thanks
Regards
Tob

Evan Balster

unread,
Jan 8, 2018, 7:19:05 PM1/8/18
to TiddlyWiki
Ordinary macros can't remove whitespace — only add.

With my formulas plugin installed, you could remove the spaces from {{!!webid}} using this macro-call:

<<formula "regexreplace({{!!webid}}, ' ', '')">>

(This would replace {{!!webid}} in your example.)


If you need to replace other kinds of whitespace like tabs, newlines, etc, you can use a slightly more general regex:

<<formula "regexreplace({{!!webid}}, '\\s+', '')">>

tobaisch

unread,
Jan 8, 2018, 8:05:45 PM1/8/18
to TiddlyWiki
And again a plugin :)
But it works great
Many Thanks Evan
Regards
Tob

tobaisch

unread,
Jan 9, 2018, 9:04:26 PM1/9/18
to TiddlyWiki
Hello Evan again,
Is there a way to make the macro output invisible if the field which is filling the macro is empty.
The macro is indeed in every Tiddler and if I have no ID-Nr only the link text is visible and the link leads to nowhere.
Since it would be better the macro or the link text would be invisible.

I can not delete it individually as it is part of a larger transclusion.
Thank you for your help
Regards
Tob

Evan Balster

unread,
Jan 9, 2018, 11:25:59 PM1/9/18
to TiddlyWiki
Hey, Tob —

I made a "condition" plugin for situations like that.  TiddlyWiki's built-in reveal widget has a similar purpose but only considers the "text" field of a target tiddler.

<$if value={{!!webid}}><$macrocall ...></$if>

tobaisch

unread,
Jan 9, 2018, 11:48:52 PM1/9/18
to tiddl...@googlegroups.com

I get an: " undefined widget 'if' "
i am not shure, but i think there sonething wrong with the import.
but it doesnt matter.
eric helped me too and his version works fine.
thanks fpr your help too, evan.
Regards
Tob


Eric Shulman

unread,
Jan 9, 2018, 11:54:35 PM1/9/18
to TiddlyWiki
On Tuesday, January 9, 2018 at 8:25:59 PM UTC-8, Evan Balster wrote:
I made a "condition" plugin for situations like that.  TiddlyWiki's built-in reveal widget has a similar purpose but only considers the "text" field of a target tiddler.

Actually, the core <$reveal> widget DOES let you compare arbitrary TextReference values.  Instead of using the "state" and "text" params, using "text" and "default" params instead.  The "default" param is used whenever the "state" param is blank **or missing**.  Thus:

<$reveal default={{!!webid}} type="match" text="">
   There is no webID
</$reveal>

Both "default" and "text" params can be used with ANY TextReference, including literals ("foo"), variables( <<foo>> ), and field references ( {{!!foo}} ).

enjoy,
-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas!" (tm)
InsideTiddlyWiki: The Missing Manuals


tobaisch

unread,
Jan 10, 2018, 12:28:46 AM1/10/18
to TiddlyWiki
thanks again Eric for your help.
It works great!
Regards Tob


Reply all
Reply to author
Forward
0 new messages