Yes - you are absolutely correct, vPeople could have been a list-type but actually both a String and a List would help more (see below). The code works as because Tinderbox is cleaver enough that if passed a string (vPeople) that has semi-colons in it that is chained to an each, it parses the string as a list.
There lies the difference in rushing through to get a solution and writing the solution as an aid for others. so, better would be:
var:string vPeopleStr;
var:list vPeopleList;
$Text.skipTo("ppl").captureLine(vPeopleStr);
vPeopleList = vPeopleStr.trim().replace(" *, *",";");
vPeopleList.each(aPerson){
var:string vPath;
vPath = create("/People",aPerson.capitalize);
$Prototype(vPath) = "Person";
$MyPeople+=aPerson.capitalize;
};
N.B. in the TBX below, $MyPeople in the last example above is updated to $MyPeopleSet for reasons with will become apparent below.
So, the process could be made more succinct, but I think it gives clarity as to the point. Thus, we:
- scan $Text for a marker, capturing the rest of that line to a variable
- we trim and tidy the string into Tinderbox list form
- we iterate the list
- in-loop we:
- make a new per-person note and apply the ‘Person’ prototype
- add the person to the stamped note’s $MyPeople
Describing that made me notice one more thing, $MyPeople is better as a Set-type so inadvertently you don’t get duplicates. The only sensible reason to use a List here is if the sorting of the list values matters. In which case, you might want to check is that person is already in the list before adding them like so:
var:string vPeopleStr;
var:list vPeopleList;
$Text.skipTo("ppl").captureLine(vPeopleStr);
vPeopleList = vPeopleStr.trim().replace(" *, *",";");
vPeopleList.each(aPerson){
var:string vPath;
var:string vPerson = aPerson.capitalize;
vPath = create("/People",vPerson);
$Prototype(vPath) = "Person";
if(!$MyPeopleList.contains(vPerson)){
$MyPeopleList+=vPerson;
}
};
I’ve updated the doc and replaced $MyPeople with a Set $MyPeopleSet and a List $MyPeopleList. There are now 2 stamps one for the Set-based method and one for the List (avoiding dupes):
Updated TBX: Parsing Separate People-ed2.tbx (242.6 KB)