Displaying contents of field with leading characters removed

Hello all

I know this is a VERY simple problem but I am afraid I cannot solve it. I want to display the contents of a field in the body of a tiddler with the first few characters removed. I have tried the $view widget with the rest operator but I cannot get the syntax right. Any help would be greatly appreciated to further my understanding.

Cheers

assuming you have a field called mydata whose value is My Data:

if the characters you want to remove are always the same (in the example below, My ), you can put this in your tiddler:

<$text text={{{ [{!!mydata}removeprefix[My ]] }}}/>

Small explanation: that code uses a TiddlyWiki widget (<$text text=.../>) to insert the result of a filter run ([{!!mydata}removeprefix[My ]]) as text in the output for your tiddler; this (“textifying” the result of the filter run) is done using a filtered transclusion ({{{ }}}).


if the prefix you want to remove is defined by a more complex criteria (e.g., “remove the first 4 characters”), try something like:

<$text text={{{ [{!!mydata}search-replace:g:regexp[....],[]] }}}/>

(see https://tiddlywiki.com/static/search-replace%20Operator.html for the details of how to use search-replace)

here’s a macro i put together to remove the first N characters, because i was sure there was an easier way than using regex:

\define removeChars(filter field numChars)
<$list filter=$filter$>
<$let chars={{{ [<currentTiddler>get[$field$]split[]nth[$numChars$]] }}}>
{{{ [<currentTiddler>split[]allafter<chars>join[]] }}}
</$let>
<<..currentTiddler>><br>
</$list>
\end

it works with my text-replacement test tiddler named ]]{{{!!test so i think it should work with any tiddler name :slight_smile:

image

It would be helpful @Rob_Jopling if you illustrated why you want to remove characters, eg what characters as an example. Because depending on this there may be other ways to do this with more useful results etc…

Hi Tony

Apologies for making my question too generic. I am developing a wiki as journal for the activities I undertake, and will act as a personal blog when I head to Scandinavia for a 3 month van trip in August.

Each journal tiddler has a title in the form:

YYYYMMDD This the title of the tiddler

The first eight characters are numbers which represent the date. The following characters are a descriptive title.

Separately I have a tiddler which lists all of the journal entries with links to the individual journal tiddlers. I want the list to show the date in the format DDth MM YYYY and below that I want to show the descriptive title. Hence my need to deconstruct the tiddler title.

I hope that helps. Really appreciate your assistance. Each answer deepens my understanding of this great app.

Cheers
R

Hi there

Many thanks for your reply which is very helpful.

The first block of code works as you have said and explains how the code works.

The second block does not appear to work as I had hoped, probably because I did not explain the problem clearly enough in the question. See amore detailed explanation of what I am trying to achieve in my response to @TW_Tones.

Many thanks

R

Hi @Rob_Jopling,

Try this:

<$text text={{{[{!!title}split[]butfirst[9]join[]]}}}/>

Have fun!

Fred

That’s great. Many thanks.

One thing I do not understand is why three sets of curly brackets are required!

R

1 Like

Three curly braces are used for “filtered tranclusions” a shorthand way to “action a filter”. If used as a value to a parameter only the first result is returned.

Personally I customise the new journal buttons to set a journal-date and use this (for listing, testing, formatting, comparison etc…) rather than deconstruct a compound title, which I use a readable form like “23rd June 2023” + more if needed. I can share them if you want.

I am so jealous :nerd_face: have fun.

Thank you Tony

I’m looking forward to the trip. I intend to send a static version of my blog psges periodically to my family.

I would be interested to see your solution as I am still not convinced mine is the most sensible.

Cheers

R

@Rob_Jopling here is a package that enhances new journal and new journal here button, to save the journal date on creation in a journal-data field. you can then run queries against that and use the title that makes sense. See Settings > Info > Basics for normal customisations title/text of new journal tiddlers. I have tested it on 5.2.7 and the 5.3.x prerelease today.

new-journals-and-journal-date.json (2.4 KB)

Once 5.3.x is released I may try and submit a revised version, to the core as it is in my mind essential.

Sorry about the delay

Many thanks Tony. I will try it out and let you know how i get on.

Cheers

R

1 Like