Concatenating strings

I have tried to follow previous entries related to concatenating text/strings and am getting more and more confused.

I want to do a simple thing, on a createtiddler action, set the basetitle of the newly created tiddler to the concatenated value of tids $:TLS/object_type> and $:/TLS/object_title with a ': ’ between them. EG ‘Book: The Bible’

I have read the macro substitution tid and substituted attribute tid as well as posts on this wiki re concatenation.

Why can’t we have a simple concatenation operator or do we already have one but I can not see its simplicity?

bobj

I believe you may be looking for the join filter operator, e.g.

$basetitle={{{ [[Book]] [[The Bible]] +[join[: ]] }}}
1 Like

I can see how that works for the text strings but in my case I need the contents of two tid’s to be concatenated, $:TLS/object_type and $:TLS/object_title with ': ’ between them. I tried various combinations using your suggested structure but can’t get it to work for me.

Thanks anyway.

bobj

Try this:

$basetitle={{{ [{$:TLS/object_type}] [{$:TLS/object_title}] +[join[: ]] }}}

-e

1 Like

Of course this is the simplest form of concatenation in wikitext.

{{$:TLS/object_type}}: {{$:/TLS/object_title}}

I addressed this and the new forms of substitution which is a key way of concatenating here Variable substitution within \procedure or \define - #3 by TW_Tones I cover a whole suit of ways.

Personally I love the new functions for this kind of thing. So I would most likely use;

\function lable()  [{$:TLS/object_type}] [[: ]] [{$:/TLS/object_title}] +[join[]]

And use <<label>> or [<label>] where needed.

  • To answer that question I would say the [join[]] operator is the concatenation operator.

However if the purpose is to simply pass something once, as a value to an attribute we now have the Substituted Attribute Values (I sometimes call these backtick attributes) which you mentioned, but perhaps overlooked them, which can concatenate text, variables and filters.

attr=`${ [{$:TLS/object_type}] [[: ]] [{$:/TLS/object_title}] +[join[]] }$`
  • So you don’t need the separately define function
    • But I think functions make my code look great attr=<<label>> as defined above.
  • Note filter expressions, are the only way to reference tiddlers and fields here in backtick attributes.
  • Tip: the text widget is good for testing these;
<$text text=`${ [{$:TLS/object_type}] [[: ]] [{$:/TLS/object_title}] +[join[]] }$`/>

If you want to create lists with a function, in an attribute do ask,
but I use " filter or list +[format:titlelist[]join[ ]]" and you may need to enlist this to use later.

2 Likes

Thanks Eric, just a simple solution.