Tinderbox Forum

Stamp that renames to first paragraph

Hey, although (I thought) I got a minimum knowledge of regex I’m failing at what seemed to be an easy task:

What’s the stamp code to rename a note’s $Name to the note’s $Text's first paragraph?

Dear Pete,
I asked a similar question here, so please take a look at it.
[[Automated way to create note titles from note text body? - #33 by WAKAMATSU]]
I am sure you will get the same solution as I did.
Why not try it?
Thx and regards, WAKAMATSU

Thank you!

In the linked thread Mark B. mentioned the words dot-operator, so I searched whether there’s also a paragraphs operator. With this getting the first paragraph works, however Tinderbox seems to randomly add a line break at the name’s end (tested with old and new Tinderboxes).

What seems to work is this:

if $Text {$Name=$Text.paragraph(0).replace("\n","")};

If anyone’s interested: I’m still curious how this could have been solved by only using regex.

Here are two approaches.

  1. $Name=$Text.paragraph[0];. I’m not getting the extra line you are.

NOTE: Original post had a typo, which is NOW fix.

  1. $Name=$Text.substr(0,25)+"...";
    This one only grabs the first 25 characters and adds a “…”.

TBX L - Simple Stamp Update Note Name with First Lines of Text.tbx (91.4 KB)

1 Like

Thanks! Did you actually try it with different Tinderboxes? Didn’t test again but I’m quite sure I randomly got a “unnecessary” line break depending on the note (or file) I tested with. BTW I tested in Outline View, not sure whether a extra line break shows up in Map View.

Yup, worked fine for me in multiple files.


1 Like

Most helpful to enabling other user here help you would be if you post a small text TBX showing the issue. If you can’t replicate the issue, that’s a sure sign the problem is more localised and might be some gremlin in a particular file.

FWIW, I often find that the simple act of making a test flags up where I’ve made a mistake in my original document. I find I’m really bad at proofing my own text/code when reading it on screen. :slight_smile:

On this point, I completely agree!!! I above going what sometimes feel like “backwards” but what I’ve find is isolating my test effort in a simple file 1) helps to focus, clears out the noise, 2) clears out any possible conflicting stuff, 3) if I really get stumped I have something to share 4) when if get it working, I have something to share, 5) I have an archive of the solution, i.e have something to share with my future self.

@mwra thanks for catching the “$$” typo. I updated the screenshot.

1 Like