trim whitespace at beginning and end of a variable

68 views
Skip to first unread message

Tony K

unread,
May 8, 2020, 4:36:04 PM5/8/20
to TiddlyWiki
Is there a way to trim whitespace at the beginning and end of a variable?
 
problem description
input box -> enter tiddler name 
button create tiddler with name entered

issue is that user sometime will add a space in the input box I don't want it in the title 

any way to solve that ?

Mat

unread,
May 8, 2020, 5:53:12 PM5/8/20
to TiddlyWiki

Tony K

unread,
May 8, 2020, 6:01:29 PM5/8/20
to TiddlyWiki
I tried it didn't work 😔 dunno what I am missing

Mat

unread,
May 8, 2020, 6:06:19 PM5/8/20
to TiddlyWiki
Could you put up a demo, e.g at tiddlyspot because that "ought to work".

<:-)

TonyM

unread,
May 8, 2020, 6:09:29 PM5/8/20
to TiddlyWiki
Tony

Best you share some code for us to look at. Try and replicate on tiddlywiki.com

It can all depend how you reference the value. Of you set a variable to a text reference it should work but using triple braces and trim if needed.

Regards
Tony

Tony K

unread,
May 8, 2020, 6:17:21 PM5/8/20
to TiddlyWiki
the code is really simple

 <$edit-text tag=input  tiddler="$:/temp/test" field="newEntry" />
<$button>
<$action-sendmessage $message="tm-new-tiddler" title={{$:/temp/test!!newEntry}} />
New Tiddler
</$button>

all i want is ignore the space I might add in the input field 

Saq Imtiaz

unread,
May 8, 2020, 6:22:07 PM5/8/20
to TiddlyWiki
title={{{ [{$:/temp/test!!newEntry}trim[]] }}}

Tony K

unread,
May 8, 2020, 6:29:32 PM5/8/20
to TiddlyWiki
wow :D

man you are amazing, been banging my head for like 2 hrs

thanks

TonyM

unread,
May 8, 2020, 7:12:24 PM5/8/20
to TiddlyWiki
Thanks Saq, Hard to code on ones mobile;
Tony K
The  triple braces and trim and other methods to handle strings in a filter is one of the best ways because unlike other methods it allows you to transform the input to a parameter after its "=" sign, without reverting to other variables or macros.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages