[TW5] Can I split tiddler title, field, etc. and manipulate?

485 views
Skip to first unread message

Penguinlay

unread,
Jan 26, 2017, 4:54:51 AM1/26/17
to tiddl...@googlegroups.com
With JS or C++, I used to split the data strings in an array, and manipulate with the result to sort the strings that end with numbers.
For example, if I have an array of strings with all entries starting with the same characters like:
["Integer = 1", "Integer = 2", "Integer = 3"], then I would split each entry string and sort by the number.

I want to do the same thing with tiddler title, field, etc. Right now, I need that feature for two usages.

First Usage
The same reasons I did with JS and C++. I have tiddlers titled similar to the entries in the above array. And, when I sort those after filter normally, nsort and sort does not work because it is not intended for this, and they sort regardless of meaning.
One way of workaround here is to name the titles including numbers not as prefix by adding leading zeros in all numbers. However, I am basically, writing data for each integers in my math notebooks, and the integers can be a million or a billion. So, it is not realistic to do so.

Second Usage
I have a macro that detect whether current tiddler is an orphan, and if it is not, then add a warning to view template along with button that opens all those tiddlers that have hard link(s) to current tiddler. That macro works fine in view template of all the tiddlers that I created (I don't know what's wrong exactly, but it did not work on system tiddlers as the warning is showing on all the system tiddlers whether it is orphan or not; I think probably because orphans operator does not work on system tiddlers. Anyway, this thread is not about this macro so that I started a new thread for that case. ... I think I know the problem now. It is the list of tiddlers filtered out by is[orphan] and its negation. I started a new thread asking for help about it here.)
I want to use the exact same macro on the exact same set of tiddlers, also in their edit templates. However, I can't reference to the title of current tiddler apparently because when I edit, draft tiddler is a separate tiddler with new name getting by prefixing with "Draft of". So, my intention is to split the title by removing "Draft of" from result of currentTiddler variable and use the result in my macro. (Or, at least, that's what I am thinking of. I am not sure if it works because draft tiddler's title might not be as simple as I thought.) Basically, it is to remind myself to change all the hard links before changing a tiddler's title.

So, how to manipulate the title, field, etc. within the capacity of what is available on official TW? Or, alternately, what is the best way to do those? I know I can always write custom JS macro or custom operator for filters or hacks into core packages but I don't know how to do it yet. So, for now, I am trying to make-do with whatever is come with TW officially.


P.S.
Texts in red are edition from original post.

Penguinlay

unread,
Jan 26, 2017, 5:23:47 AM1/26/17
to tiddl...@googlegroups.com
I just found string operators in documentation, finally. 😅
I will try those out now, and come back here if I have any questions. 😅


On Thursday, January 26, 2017 at 1:54:51 AM UTC-8, Penguinlay wrote:
With JS or C++, I used to split the data strings in an array, and manipulate with the result to sort the strings that end with numbers.
For example, if I have an array of strings with all entries starting with the same characters like:
["Integer = 1", "Integer = 2", "Integer = 3"], then I would split each entry string and sort by the number.

I want to do the same thing with tiddler title, field, etc. Right now, I need that feature for two usages.

First Usage
The same reasons I did with JS and C++. I have tiddlers titled similar to the entries in the above array. And, when I sort those after filter normally, nsort and sort does not work because it is not intended for this, and they sort regardless of meaning.
One way of workaround here is to name the titles including numbers not as prefix by adding leading zeros in all numbers. However, I am basically, writing data for each integers in my math notebooks, and the integers can be a million or a billion. So, it is not realistic to do so.

Second Usage
I have a macro that detect whether current tiddler is an orphan, and if it is not, then add a warning to view template along with button that opens all those tiddlers that have hard link(s) to current tiddler. That macro works fine in view template of all the tiddlers that I created (I don't know what's wrong exactly, but it did not work on system macro as the warning is showing on all the system tiddlers whether it is orphan or not; I think probably because orphans operator does not work on system tiddlers. Anyway, this thread is not about this macro so that I started a new thread for that case.)
I want to use the exact same macro on the exact same set of tiddlers, also in their edit templates. However, I can't reference to the title of current tiddler apparently because when I edit, draft tiddler is a separate tiddler with new name getting by prefixing with "Draft of". So, my intention is to split the title by removing "Draft of" from result of currentTiddler variable and use the result in my macro. (Or, at least, that's what I am thinking of. I am not sure if it works because draft tiddler's title might not be as simple as I thought.) Basically, it is to remind myself to change all the hard links before changing a tiddler's title.

Mat

unread,
Jan 26, 2017, 6:10:12 AM1/26/17
to tiddl...@googlegroups.com
@Penguinlay - see also Tobias Beers recently updated split. I think you will appreciate it very much.

<:-)

Penguinlay

unread,
Jan 26, 2017, 6:48:09 AM1/26/17
to tiddl...@googlegroups.com
Thank, @Mat! I will try it out after sleep because it's way past my sleep time now. :)
Reply all
Reply to author
Forward
0 new messages