Hello The Bo: Thanks for the code. It looks like is should work...

But, in tiddlywiki.com, I 

1 - Created a new tiddler with these fields:
title: $:/substring_from_to
type: application/javascript
module-type: macro
tag: $:/tags/Macro
text: copied all lines provided

2 - Created a new tiddler with no tags, no fields other than text:

Usage: (even with a Filter)<br>
<$list filter="[!is[system]!is[shadow]tag[HelloThere]]">
1 <<currentTiddler>><br>
2 <$link to=<<currentTiddler>>> <<substr "0" "5">> </$link><br>
</$list> 


For my line 1, I got tiddler names. For my line 2, I had nothing returned. 
:(

Any help, much appreciated. This looks very promising, and exactly what I 
had hoped to have.

//steve.



On Monday, March 20, 2017 at 6:13:46 AM UTC-4, The Bo wrote:
>
> Hey,
>
> you could try it with a "substring" macro like this:
>
> /*\
> title: $:/substring_from_to
> type: application/javascript
> module-type: macro
>
> A macro to get certain characters from a string.
>
> \*/
> (function(){
>
> /*jslint node: true, browser: true */
> /*global $tw: false */
> "use strict";
>
> /*
> Information about this macro
> */
>
> exports.name = "substr";
> exports.params = [
>                               {name: "from",default:"0"},
>                               {name: "to", default:"0"}
> ]; 
> /*
> Run the macro
> */
> exports.run = function(from, to) {
>
> var tiddlertitle = this.getVariable("currentTiddler");
>      if (to !== "0") {
>      return tiddlertitle.substring(from,to);
>      } else {
>      return tiddlertitle.substring(from);
>     }
>
> };
> })();
>
> tag: $:/tags/Macro
> type: application/javascript
> module-type: macro
>
>
> Usage: (even with a Filter)
> <$list filter="[!is[system]!is[shadow]tag[yourTag]]">
>
> <$link to=<<currentTiddler>>><<substr "0" "5">></$link>
>
>
> Regards,
> The Bo
>
> Am Freitag, 17. März 2017 22:13:00 UTC+1 schrieb stevesuny:
>>
>>  Hi, 
>>
>> this topic seems to have come up before, but without a clear answer.
>>
>> How do I define a substring with  the first x characters of a tiddler 
>> name?
>>
>> If I have $tiddler$ named "01 01 Long name of tiddler" (those are spaces) 
>> I'd like to be extract "01 01" to <<short-name>> so I can write <$link 
>> to="$tiddler$><<short-name>></$link> to display "01 01" as a link.
>>
>> Thanks!
>>
>> (It seems I could play with prefix, but I kind of messed up with my 
>> tiddler names by having two spaces, so I can't make a prefix of the first 
>> five characters...)
>>
>> //steve.
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywiki+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/1624c9ff-8c18-4618-9813-2473af222dfc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to