replace operator

108 views
Skip to first unread message

Mohammad

unread,
Mar 29, 2020, 2:28:50 AM3/29/20
to TiddlyWiki
There is a replcae operator one can found it and examples here



I appreciate if somebody explain what is the purpose of this operator and give a real use-case!


--Mohammad

TonyM

unread,
Mar 29, 2020, 3:26:31 AM3/29/20
to TiddlyWiki
Mohammad

Its on tiddlywiki.com as well and seems to have being around for a while.

If you look at the examples it allows you to replace one title with with another. The last example that shows today.

As this was possibly developed before split and join operators, I expect we have not explored the combination of these operators fully.

Split[] will split the input into characters removing space as a delimiter. You could then replace something and join it back together.

Regards
Tony

Mohammad

unread,
Mar 29, 2020, 3:39:49 AM3/29/20
to TiddlyWiki
Tony!
 I am looking for string operations in TW5.1.22 and it seems it has several features

Look



But I dont understand some of operators like replace and it seems it has some special usecase!

Considering the substr and SnR in commander, I think one can do many string operation in TW.

--Mohammad

Mohammad

unread,
Mar 29, 2020, 3:56:19 AM3/29/20
to tiddl...@googlegroups.com
We also have trim, like

<$vars x=" a b ">
{{{
[<x>trim[]]
}}}
</$vars>

The triml and trimr can be written as below


\define triml(string) {{{ [<__string__>addsuffix[/]trim[]removesuffix[/]]  }}}
\define trimr(string) {{{ [<__string__>addprefix[/]trim[]removeprefix[/]]  }}}

The only issue is TW condenses the space into one. for example if you give [  a    b  ], trim returns [a b]
and I think this is okay in most cases.

--Mohammad

Mohammad

unread,
Mar 29, 2020, 4:21:29 AM3/29/20
to TiddlyWiki
Post edited. 
For email readers:

Mark S.

unread,
Mar 29, 2020, 12:47:00 PM3/29/20
to TiddlyWiki
It's more about list manipulation rather than string manipulation. But you could use it for string manipulation like this:

<$vars mystr="The knights who say ni">
<$list filter="[<mystr>split[ ]] doctors +[replace[knights]join[ ]]"/>
</$vars>

Extended to a larger group, this version will change "Operator" to "Function" for items at tiddlywiki.com

<$list filter="[regexp:title[\bOperator\b]!search:title[Example]]" variable="mystr">
<$list filter="[<mystr>split[ ]] Function +[replace[Operator]join[ ]]">

</$list>
</$list>

Mohammad

unread,
Mar 29, 2020, 1:16:33 PM3/29/20
to TiddlyWiki
Mark,
 Thank you for explanation and examples

--Mohammad

Mohammad

unread,
Mar 29, 2020, 1:18:26 PM3/29/20
to TiddlyWiki
Added to TW-Scripts.


On Sunday, March 29, 2020 at 9:17:00 PM UTC+4:30, Mark S. wrote:

TonyM

unread,
Mar 29, 2020, 7:54:02 PM3/29/20
to TiddlyWiki
Mark

Yes replace title not string. I remember a cobol statement called inspect that allowed both search and replace anything in a string without the complex minamilisium of regexe.

It would be a start if we could get split[] not to remove spaces, but I don't know how. Because a title can't be a space.

Regards
Tony

Reply all
Reply to author
Forward
0 new messages