Tinderbox Forum

Coerce string to number?

Is this possible? I want to make a “map spreadsheet” using a note’s name (ideally) as a “cell”. The first thing I need to be able to do is coerce that text number into an actual number.

Or is it better to deploy user attributes for this?

Thanks in advance (and sorry if the answer is in obvious place that I missed on my initial searches).

If $Name is ‘1’ then:

$MyNumber = $Name

If more control is needed use look at String.toNumber.

1 Like

How did I miss that!? It took some work. Was positive I’d searched for it, but obviously not well enough. Thanks!

1 Like

As a follow up, when referencing a note with a constantly changing $Name, I’m assuming that using its $ID is probably the best way, right? Or is there some other trick that’s even better?

Thanks in advance.

Yes, $ID is the unique ID of notes, agents, aliases, etc., within Tinderbox. The ID persists through renaming and is also why it is possible to have more than one note with the same name† in a document. The $ID UID number is thus unique within a single TBX. If items are copied to other documents the pasted item is given a new $ID.

Here is (part of) the source XML of a TBX document. There are two notes defined:

In each case the main object representing the note is an <item> tag that has one XML attribute, ID i.e. it’s $ID. The note title ($Name) is an XML attribute of the <item>. See that the second note’s <item> is nested within the first one. This is how the canonical outline structure of the document is reflected; that outline is also reflected in a note’s $Path.

† Note names can be duplicates but be aware they don’t play well with action code, similarly notes with no $Name (i.e. a blank string). If there are two notes called “X” in the same container/map, they both have the same $Path. When action code is given a $Name as a parameter it actually uses the $Path and when the latter is resolved to the item first by $Outline Order. So if trying to automatically link to two items with the same $Path both links will point to the item with the lowest $OutlineOrder (at the time); this is unlikely to be the desired intent. So beware if using duplicate names.

1 Like