Implementing the $Text.eachline()

I am very much a novice at this agent/action/stamp business and I am not able to get the $Text.eachline() statement to work. I was working off the example from the July 13 Tinderbox Meetup where Michael Becker was using this statement in his example.

My use case: I have imported several Kindle Highlights from Obsidian with YAML properties that have the same attribute names in Tinderbox. I am attempting to parse the $Text in Tinderbox which contains those lines of YAML properties. My approach, in a stamp so far, is as follows:

$Text.eachline(aLine) {

  if (aLine.contains("zIndexTerm")) {

     $zIndexTerm=aLine.substr(12);
  };

};

Where there is a line in the $Text attribute zIndexTerm Insulin Resistance Symptoms

The resolution on my computer screen makes it very difficult to replicate the patterns in the Tinderbox Meetup YouTube (around time stamp 1:30) to distinguish parentheses from brackets from semi-colons.

I suspect there is something outside of this action in a stamp that is affecting the conditional if (aLine.contains(ā€œzIndexTermā€)){} as it never becomes true.

I have retyped that line in the $Text attribute to eliminate the possibility that there are hidden characters in the text to prevent a positive match.

I am in need of some words of wisdom.

The operator is .eachLine(), with an interstitial capital ā€˜Lā€™. Operator names are case-sensitive so using .eachline() fails. Generally, action operators that are compunded words inter-capialtise the word boundary, thus ā€˜each+lineā€™ ā†’ ā€˜eachLineā€™.

Using your code with the correct syntax works for me. Run stamp ā€˜Testā€™ on ā€˜A noteā€™ in this demo file: eachLine-demo.tbx (167.2 KB)

See more on the String.eachLine(loopVar[:condition]){actions} operator.

HTH :slight_smile:

Thank you very much. Another example, for me, of staring at something for days and just not seeing what I was looking at. Yes, I have made extensive reference to aTbRef but just failed to pick up the essence of the camel-case syntax in this case. And yes, it certainly does work for me now. A major roadblock for me has now been overcome. Again, thank you. A second pair of eyes is invaluable.

2 Likes

No worries. No judgement here, not least as Iā€™m a poor typist so even if I think the right word/spelling, the wrong one comes out.

There is some contextual help in some spaces: the article Coloured syntax highlighting in Action code gives more detail.

For example, here Iā€™m experimenting in the Rule Inspector (a place that has the colouring described above). First as you type (and after at least 3 characters you may see an autocomplete):

Next, if you type an operator name incorrectly (including case), it wonā€™t colour blue (see link above for colour meanings):

Action Inspector: untitled 2024-08-01 16-14-47

Unbalanced brackets are also highlighted. I edited the above showing a closing parenthesis and an opening curly bracket highlighted as its opening/closing partner canā€™t be found.

Action Inspector: untitled 2024-08-01 16-18-40

Be aware that you might be using strings that are adding single brackets so the latter can sometimes indicate a missing partner. In the example below, we can see there is no error but the regex doing the colour code cannot (such methods have limits - this isnā€™t a programming IDE!):

Action Inspector: untitled 2024-08-01 16-22-03

Anyway, the colouring is another thing to consider if staring at code that ought to work but doesnā€™t seem to. :slight_smile:

1 Like